newsworthycharts 1.71.5__py3-none-any.whl → 1.72.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- __version__ = "1.71.5"
1
+ __version__ = "1.72.0"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -8,6 +8,7 @@ import pandas as pd
8
8
  import mapclassify
9
9
  import matplotlib as mpl
10
10
  import matplotlib.patches as mpatches
11
+ from mpl_toolkits.axes_grid1.inset_locator import inset_axes
11
12
 
12
13
 
13
14
  class ChoroplethMap(Map):
@@ -61,6 +62,32 @@ class ChoroplethMap(Map):
61
62
  df["color"] = df["color"].fillna("gainsboro")
62
63
  args["color"] = df["color"]
63
64
 
65
+ self._fig.tight_layout()
66
+ fmt = self._get_value_axis_formatter()
67
+ cax = inset_axes(
68
+ self.ax,
69
+ width=0.1,
70
+ height=2, # 2 tum = 200 px vid 100 dpi
71
+ loc='upper right',
72
+ borderpad=0.1,
73
+ # formatter
74
+ )
75
+ cb = self._fig.colorbar(
76
+ mapper,
77
+ cax=cax,
78
+ format=mpl.ticker.FuncFormatter(fmt),
79
+ drawedges=False,
80
+ shrink=0.9,
81
+ # use_gridspec=False,
82
+ # pad=0.1,
83
+ )
84
+ # args["legend_kwds"]["pad"] = 0.15
85
+ # args["legend_kwds"]["location"] = "left"
86
+
87
+ if self.legend_title:
88
+ cb.set_label(self.legend_title)
89
+ self.legend_title = None
90
+ """
64
91
  _min = df["data"].min()
65
92
  _max = df["data"].max()
66
93
  _median = df["data"].median()
@@ -70,6 +97,7 @@ class ChoroplethMap(Map):
70
97
  patches.append(mpatches.Patch(color=mapper.to_rgba(_median), label=fmt(_median)))
71
98
  if _max != _min:
72
99
  patches.append(mpatches.Patch(color=mapper.to_rgba(_max), label=fmt(_max)))
100
+ """
73
101
 
74
102
  elif not self.categorical:
75
103
  # mapclassify doesn't work well with nan values,
@@ -99,7 +127,7 @@ class ChoroplethMap(Map):
99
127
  # args["cmap"] = self.color_ramp
100
128
  # We can not provide vmin/vmax to geopandas, so we need to
101
129
  # normalize the data ourselves, otherwise the inset maps will be off
102
- norm = mpl.colors.Normalize(vmin=df["data"].min(), vmax=df["data"].max())
130
+ norm = mpl.colors.Normalize(vmin=_has_value["data"].min(), vmax=_has_value["data"].max())
103
131
  mapper = mpl.cm.ScalarMappable(norm=norm, cmap=self.color_ramp)
104
132
  df["color"] = df["data"].apply(lambda x: mapper.to_rgba(x) if not np.isnan(x) else "gainsboro")
105
133
  df["color"] = df["color"].fillna("gainsboro")
@@ -155,7 +183,7 @@ class ChoroplethMap(Map):
155
183
  patch = mpatches.Patch(color=color, label=label)
156
184
  patches.append(patch)
157
185
  patches = list(reversed(patches))
158
- if self.missing_label:
186
+ if self.missing_label and len(patches):
159
187
  patches.append(mpatches.Patch(color="gainsboro", label=self.missing_label))
160
188
 
161
189
  df.plot(ax=self.ax, **args)
@@ -201,3 +229,4 @@ class ChoroplethMap(Map):
201
229
  handles=patches,
202
230
  **label_kwargs,
203
231
  )
232
+ #self.ax.get_figure().savefig("TST.png", bbox_inches="tight")
newsworthycharts/map.py CHANGED
@@ -95,6 +95,7 @@ class Map(Chart):
95
95
  self.base_map = None
96
96
  self.missing_label = None
97
97
  self.df = None
98
+ self.show_ticks = False
98
99
 
99
100
  def _normalize_region_code(self, code):
100
101
  code = code.upper().replace("_", "-")
@@ -148,9 +148,15 @@ class BumpChart(SerialChart):
148
148
  # To save time we'll only measure the with of the longest text string
149
149
  # There will be edge cases where shorter strings taker up more space
150
150
  longest_sp_label = max([len(str(x[1])) for x in startpoints])
151
- dummy_text = self.ax.text(0, 0, longest_sp_label, fontsize=self._nwc_style["annotation.fontsize"])
151
+ dummy_text = self.ax.text(
152
+ 0, 0,
153
+ longest_sp_label,
154
+ fontsize=self._nwc_style["annotation.fontsize"]
155
+ )
152
156
  _bbox = dummy_text.get_window_extent(renderer=self._fig.canvas.get_renderer())
153
- self.ax.spines['left'].set_position(('outward', _bbox.width * 1.15 + 15)) # Add a bit extra space
157
+ self.ax.spines['left'].set_position(
158
+ ('outward', _bbox.width * 1.15 + 15)
159
+ )
154
160
  dummy_text.remove()
155
161
 
156
162
  if self.label_placement in ["right", "both"]:
@@ -520,7 +520,7 @@ class SerialChart(Chart):
520
520
  linewidth=1,
521
521
  color="#444444",
522
522
  zorder=11,
523
- linestyle="--" if self.baseline else "-"
523
+ linestyle="--" if self.baseline else "-",
524
524
  )
525
525
  if self.baseline_annotation:
526
526
  xy = (to_date(self.data.outer_min_x), self.baseline)
@@ -531,6 +531,7 @@ class SerialChart(Chart):
531
531
  xy,
532
532
  direction="down" if first_val and first_val >= self.baseline else "up",
533
533
  color=self._nwc_style["neutral_color"],
534
+ zorder=11,
534
535
  )
535
536
 
536
537
  # Shade area between lines if there are exactly 2 series
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.71.5
3
+ Version: 1.72.0
4
4
  Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
5
  Home-page: https://github.com/jplusplus/newsworthycharts
6
- Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.71.5.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.72.0.tar.gz
7
7
  Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
8
  Author-email: stockholm@jplusplus.org
9
9
  License: MIT
@@ -11,7 +11,7 @@ Requires-Python: >=3.9
11
11
  Description-Content-Type: text/x-rst
12
12
  License-File: LICENSE.txt
13
13
  Requires-Dist: boto3 >=1.26
14
- Requires-Dist: matplotlib ==3.10.0
14
+ Requires-Dist: matplotlib ==3.10.1
15
15
  Requires-Dist: langcodes >=3.3
16
16
  Requires-Dist: Babel <3,>=2.14.0
17
17
  Requires-Dist: PyYAML >=3
@@ -271,6 +271,15 @@ Roadmap
271
271
  Changelog
272
272
  ---------
273
273
 
274
+ - 1.72.0
275
+
276
+ - Use gradient legend för continuous choropleth maps
277
+ - Don't add None value to legend if it is empty in ChoroplethMap
278
+ - Fixed zorder bug in SerialChart with baseline annotations and bars
279
+ - matplotlib==3.10.1
280
+ - Fixed a bug where choropleth maps would break on svery small numbers (by bypassing all axis formatting logic for maps).
281
+ This should also speed up rendering of maps somewhat.
282
+
274
283
  - 1.71.5
275
284
 
276
285
  - zorder fixes in BumpChart
@@ -1,15 +1,15 @@
1
- newsworthycharts/__init__.py,sha256=pPubTzsF-HxZnryr86J7ir5eaH5q595foyBekjtB-9s,1221
1
+ newsworthycharts/__init__.py,sha256=RGNp0faDG-9SuFh6Ha4f8TB-QT5j3WSTn1gcqdIANhk,1221
2
2
  newsworthycharts/bubblemap.py,sha256=nkocWmpiFgfjEuJGAsthjY5X7Q56jXWsZHUGXw4PwgE,2587
3
3
  newsworthycharts/categoricalchart.py,sha256=Vr-0yFms0hEVCeUa3vLt3FYBqpX4xLQ8YGPc4LGQN_A,18368
4
4
  newsworthycharts/chart.py,sha256=eXgrNCmfE52rFsvTDkMpCZsmL0oSezdkH---LGYsES8,35062
5
- newsworthycharts/choroplethmap.py,sha256=Si-01213rWqDKINkhmKV6x5iSMumQveJfrlCnqYcIJM,8173
5
+ newsworthycharts/choroplethmap.py,sha256=PEhBOw9UD0OyeFRjpCFFoxa2ztT5NeGSYOubo2PaNtA,9210
6
6
  newsworthycharts/datawrapper.py,sha256=RRkAVTpfP4updKxUIBaSmKuBi2RUVPaBRF8HDQhlGGA,11250
7
- newsworthycharts/map.py,sha256=c409jEO4L8Yr780sJRC0RchR44roAlgOUDAkuk1SfRg,6057
7
+ newsworthycharts/map.py,sha256=EGh96tU10y7Kgu1e83_VWQSeABdjP6V-0VM6VTHDxu4,6089
8
8
  newsworthycharts/rangeplot.py,sha256=NE1W9TnmlpK6T3RvBJOU3nd73EXqkj17OY9i5zlw_cQ,8366
9
- newsworthycharts/rankchart.py,sha256=1wn2ZP67xH-F_Wz-XnTOr2gAXMXMCufe6eFRHXY7Fms,9285
9
+ newsworthycharts/rankchart.py,sha256=vMzNMVOv1jae6wuHC_riAdb1lm9oPltO3TT3YQpc0Oc,9376
10
10
  newsworthycharts/scatterplot.py,sha256=weHubdMsDGaBTXejg2TqBNPTQ1K-QBpZqJiyQ8EOEc4,5084
11
11
  newsworthycharts/seasonalchart.py,sha256=rr55yqJUkaYDR9Ik98jes6574oY1U8t8LwoLE3gClW4,1967
12
- newsworthycharts/serialchart.py,sha256=gy5BIOrzte529JFII1jFbEDDejnB7FmO_kzDHXdE21o,30105
12
+ newsworthycharts/serialchart.py,sha256=x28ldRdba3JEmat-cnQH1XQQXrPEhx-S55_1yTvNIDI,30133
13
13
  newsworthycharts/storage.py,sha256=myERhlpvXyExXxUByBq9eW1bWkCyfH9SwTZbsWSyy3Q,4301
14
14
  newsworthycharts/stripechart.py,sha256=9B6PX2MyLuKNQ8W0OGdKbP0-U32kju0K_NHHwwz_J68,1547
15
15
  newsworthycharts/custom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -29,8 +29,8 @@ newsworthycharts/rc/newsworthy,sha256=yOIZvYS6PG1u19VMcdtfj9vbihKQsey5IprwqK59Kg
29
29
  newsworthycharts/translations/datawrapper_regions.csv,sha256=fzZcQRX6RFMlNNP8mpgfYNdR3Y0QAlQxDXk8FXTaWWI,9214
30
30
  newsworthycharts/translations/regions.py,sha256=Nv1McQjggD4S3JRu82rDMTG3pqUVR13E5-FBpSYbm98,239
31
31
  newsworthycharts/translations/se_municipalities.csv,sha256=br_mm-IvzQtj_W55_ATREhJ97jWnCweBFlDAVY2EBxA,7098
32
- newsworthycharts-1.71.5.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
33
- newsworthycharts-1.71.5.dist-info/METADATA,sha256=QBAoSQvoGUQgik45tPfmTO43h2Zwu8nc_U1xxJoBjHQ,33612
34
- newsworthycharts-1.71.5.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
35
- newsworthycharts-1.71.5.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
36
- newsworthycharts-1.71.5.dist-info/RECORD,,
32
+ newsworthycharts-1.72.0.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
33
+ newsworthycharts-1.72.0.dist-info/METADATA,sha256=uGw146ThyPklZETg3rtINrRMYmr7Y2w5VsI8MUX1fHM,34022
34
+ newsworthycharts-1.72.0.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
35
+ newsworthycharts-1.72.0.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
36
+ newsworthycharts-1.72.0.dist-info/RECORD,,