newsworthycharts 1.60.1__tar.gz → 1.61.0__tar.gz

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.
Files changed (51) hide show
  1. {newsworthycharts-1.60.1/newsworthycharts.egg-info → newsworthycharts-1.61.0}/PKG-INFO +22 -11
  2. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/README.rst +18 -7
  3. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/__init__.py +1 -1
  4. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/choroplethmap.py +31 -8
  5. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/map.py +1 -0
  6. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0/newsworthycharts.egg-info}/PKG-INFO +22 -11
  7. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts.egg-info/requires.txt +2 -2
  8. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/setup.py +2 -2
  9. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/LICENSE.txt +0 -0
  10. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/MANIFEST.in +0 -0
  11. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/bubblemap.py +0 -0
  12. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/categoricalchart.py +0 -0
  13. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/chart.py +0 -0
  14. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/custom/__init__.py +0 -0
  15. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/custom/climate_cars.py +0 -0
  16. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/datawrapper.py +0 -0
  17. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/__init__.py +0 -0
  18. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/color_fn.py +0 -0
  19. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/colors.py +0 -0
  20. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/datalist.py +0 -0
  21. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/formatter.py +0 -0
  22. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/geography.py +0 -0
  23. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/locator.py +0 -0
  24. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/mimetypes.py +0 -0
  25. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/lib/utils.py +0 -0
  26. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/maps/se-4.gpkg +0 -0
  27. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/maps/se-7.gpkg +0 -0
  28. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/rangeplot.py +0 -0
  29. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/rc/newsworthy +0 -0
  30. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/scatterplot.py +0 -0
  31. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/seasonalchart.py +0 -0
  32. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/serialchart.py +0 -0
  33. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/storage.py +0 -0
  34. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/stripechart.py +0 -0
  35. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/translations/datawrapper_regions.csv +0 -0
  36. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/translations/regions.py +0 -0
  37. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts/translations/se_municipalities.csv +0 -0
  38. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts.egg-info/SOURCES.txt +0 -0
  39. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts.egg-info/dependency_links.txt +0 -0
  40. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts.egg-info/not-zip-safe +0 -0
  41. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/newsworthycharts.egg-info/top_level.txt +0 -0
  42. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/setup.cfg +0 -0
  43. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_categorical_chart.py +0 -0
  44. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_choropleth_maps.py +0 -0
  45. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_custom_climate_cars.py +0 -0
  46. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_data_list.py +0 -0
  47. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_datawrapper.py +0 -0
  48. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_main.py +0 -0
  49. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_rangeplot.py +0 -0
  50. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_scatterplot.py +0 -0
  51. {newsworthycharts-1.60.1 → newsworthycharts-1.61.0}/test/test_serial_chart.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.60.1
3
+ Version: 1.61.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.60.1.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.61.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
@@ -21,9 +21,9 @@ Requires-Dist: python-dateutil<3,>=2
21
21
  Requires-Dist: Pillow==10.4.0
22
22
  Requires-Dist: requests>=2.22
23
23
  Requires-Dist: matplotlib-label-lines==0.5.1
24
- Requires-Dist: geopandas>1
24
+ Requires-Dist: geopandas>=1
25
25
  Requires-Dist: mapclassify==2.6.1
26
- Requires-Dist: fiona>=1.10
26
+ Requires-Dist: puremagic>=1
27
27
 
28
28
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
29
29
 
@@ -188,13 +188,14 @@ These settings are available for all chart types:
188
188
 
189
189
  **Map**
190
190
 
191
- - bins = 9 # Number of bins for continuous data
192
- - binning_method = "natural_breaks"
193
- - colors = None
194
- - color_ramp = "YlOrRd"
195
- - categorical = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
196
- - base_map = None
197
- - missing_label = None # Add a label for no data
191
+ - `use_bins` = True # If False, the map will be colored by a continuous value
192
+ - `bins` = 5 # Number of bins for continuous data
193
+ - `binning_method` = "natural_breaks"
194
+ - `colors` = None
195
+ - `color_ramp` = "YlOrRd"
196
+ - `categorical` = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
197
+ - `base_map` = None
198
+ - `missing_label` = None # Add a label for no data
198
199
 
199
200
  `basemap` can be `{ISO}-{level}` or `{ISO}|{subset}-{level}`.
200
201
  For example, `se-4` will show Swedish counties, while `se|03-7` will show municipalities (`se-7`) starting with `03`.
@@ -203,6 +204,10 @@ For example, `se-4` will show Swedish counties, while `se|03-7` will show munici
203
204
 
204
205
  _ Inherits from Map _
205
206
 
207
+ **BubbleMap**
208
+
209
+ _ Inherits from Map _
210
+
206
211
  **ProgressChart**
207
212
 
208
213
  **RangePlot**
@@ -247,6 +252,12 @@ Roadmap
247
252
  Changelog
248
253
  ---------
249
254
 
255
+ - 1.61.0
256
+
257
+ - Added non-binned color ramp support to ChoroplethMap, with `use_bins=False`
258
+ - Improved data validation in ChoroplethMap
259
+ - Put largest value on top in choropleth map legends
260
+
250
261
  - 1.60.1
251
262
 
252
263
  - Don't require fiona. Geopandas now support Pyogrio
@@ -161,13 +161,14 @@ These settings are available for all chart types:
161
161
 
162
162
  **Map**
163
163
 
164
- - bins = 9 # Number of bins for continuous data
165
- - binning_method = "natural_breaks"
166
- - colors = None
167
- - color_ramp = "YlOrRd"
168
- - categorical = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
169
- - base_map = None
170
- - missing_label = None # Add a label for no data
164
+ - `use_bins` = True # If False, the map will be colored by a continuous value
165
+ - `bins` = 5 # Number of bins for continuous data
166
+ - `binning_method` = "natural_breaks"
167
+ - `colors` = None
168
+ - `color_ramp` = "YlOrRd"
169
+ - `categorical` = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
170
+ - `base_map` = None
171
+ - `missing_label` = None # Add a label for no data
171
172
 
172
173
  `basemap` can be `{ISO}-{level}` or `{ISO}|{subset}-{level}`.
173
174
  For example, `se-4` will show Swedish counties, while `se|03-7` will show municipalities (`se-7`) starting with `03`.
@@ -176,6 +177,10 @@ For example, `se-4` will show Swedish counties, while `se|03-7` will show munici
176
177
 
177
178
  _ Inherits from Map _
178
179
 
180
+ **BubbleMap**
181
+
182
+ _ Inherits from Map _
183
+
179
184
  **ProgressChart**
180
185
 
181
186
  **RangePlot**
@@ -220,6 +225,12 @@ Roadmap
220
225
  Changelog
221
226
  ---------
222
227
 
228
+ - 1.61.0
229
+
230
+ - Added non-binned color ramp support to ChoroplethMap, with `use_bins=False`
231
+ - Improved data validation in ChoroplethMap
232
+ - Put largest value on top in choropleth map legends
233
+
223
234
  - 1.60.1
224
235
 
225
236
  - Don't require fiona. Geopandas now support Pyogrio
@@ -1,4 +1,4 @@
1
- __version__ = "1.60.1"
1
+ __version__ = "1.61.0"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -6,6 +6,7 @@ import geopandas as gpd
6
6
  import numpy as np
7
7
  import pandas as pd
8
8
  import mapclassify
9
+ import matplotlib as mpl
9
10
  import matplotlib.patches as mpatches
10
11
 
11
12
 
@@ -50,11 +51,33 @@ class ChoroplethMap(Map):
50
51
  }
51
52
 
52
53
  patches = [] # for legend
53
- if not self.categorical:
54
+ if not self.categorical and self.use_bins is False:
55
+ # We can not provide vmin/vmax to geopandas, so we need to
56
+ # normalize the data ourselves, otherwise the inset maps will be off
57
+ norm = mpl.colors.Normalize(vmin=df["data"].min(), vmax=df["data"].max())
58
+ mapper = mpl.cm.ScalarMappable(norm=norm, cmap=self.color_ramp)
59
+ df["color"] = df["data"].apply(lambda x: mapper.to_rgba(x) if not np.isnan(x) else "gainsboro")
60
+ df["color"] = df["color"].fillna("gainsboro")
61
+ args["color"] = df["color"]
62
+
63
+ _min = df["data"].min()
64
+ _max = df["data"].max()
65
+ _median = df["data"].median()
66
+ fmt = self._get_value_axis_formatter()
67
+ patches.append(mpatches.Patch(color=mapper.to_rgba(_min), label=fmt(_min)))
68
+ if _median != _min and _median != _max:
69
+ patches.append(mpatches.Patch(color=mapper.to_rgba(_median), label=fmt(_median)))
70
+ if _max != _min:
71
+ patches.append(mpatches.Patch(color=mapper.to_rgba(_max), label=fmt(_max)))
72
+
73
+ elif not self.categorical:
54
74
  # mapclassify doesn't work well with nan values,
55
75
  # but we to keep them for plotting, hence
56
76
  # this hack with cutting out nan's and re-pasting them below
57
77
  _has_value = df[~df["data"].isna()].copy()
78
+ if not pd.to_numeric(_has_value['data'], errors='coerce').notnull().all():
79
+ # We can't bin non-numeric data
80
+ raise ValueError("Data must be numeric")
58
81
  binning = mapclassify.classify(
59
82
  np.asarray(_has_value["data"]), # .astype("category")
60
83
  self.binning_method,
@@ -75,10 +98,8 @@ class ChoroplethMap(Map):
75
98
  # args["cmap"] = self.color_ramp
76
99
  # We can not provide vmin/vmax to geopandas, so we need to
77
100
  # normalize the data ourselves, otherwise the inset maps will be off
78
- import matplotlib.cm as cm
79
- import matplotlib as mpl
80
101
  norm = mpl.colors.Normalize(vmin=df["data"].min(), vmax=df["data"].max())
81
- mapper = cm.ScalarMappable(norm=norm, cmap=self.color_ramp)
102
+ mapper = mpl.cm.ScalarMappable(norm=norm, cmap=self.color_ramp)
82
103
  df["color"] = df["data"].apply(lambda x: mapper.to_rgba(x) if not np.isnan(x) else "gainsboro")
83
104
  df["color"] = df["color"].fillna("gainsboro")
84
105
  args["color"] = df["color"]
@@ -130,6 +151,7 @@ class ChoroplethMap(Map):
130
151
  color = self._nwc_style[f"{color}_color"]
131
152
  patch = mpatches.Patch(color=color, label=label)
132
153
  patches.append(patch)
154
+ patches = list(reversed(patches))
133
155
  if self.missing_label:
134
156
  patches.append(mpatches.Patch(color="gainsboro", label=self.missing_label))
135
157
 
@@ -171,7 +193,8 @@ class ChoroplethMap(Map):
171
193
  for _line in [a, b, c, d]:
172
194
  _line.set_visible(False)
173
195
 
174
- self.ax.legend(
175
- handles=patches,
176
- **label_kwargs,
177
- )
196
+ if len(patches):
197
+ self.ax.legend(
198
+ handles=patches,
199
+ **label_kwargs,
200
+ )
@@ -87,6 +87,7 @@ class Map(Chart):
87
87
  def __init__(self, *args, **kwargs):
88
88
  super(Map, self).__init__(*args, **kwargs)
89
89
  self.bins = kwargs.get("bins", 5)
90
+ self.use_bins = kwargs.get("use_bins", True)
90
91
  self.binning_method = kwargs.get("binning_method", "natural_breaks")
91
92
  self.colors = kwargs.get("colors", None)
92
93
  self.color_ramp = kwargs.get("color_ramp", "YlGn") # YlOrRd
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.60.1
3
+ Version: 1.61.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.60.1.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.61.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
@@ -21,9 +21,9 @@ Requires-Dist: python-dateutil<3,>=2
21
21
  Requires-Dist: Pillow==10.4.0
22
22
  Requires-Dist: requests>=2.22
23
23
  Requires-Dist: matplotlib-label-lines==0.5.1
24
- Requires-Dist: geopandas>1
24
+ Requires-Dist: geopandas>=1
25
25
  Requires-Dist: mapclassify==2.6.1
26
- Requires-Dist: fiona>=1.10
26
+ Requires-Dist: puremagic>=1
27
27
 
28
28
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
29
29
 
@@ -188,13 +188,14 @@ These settings are available for all chart types:
188
188
 
189
189
  **Map**
190
190
 
191
- - bins = 9 # Number of bins for continuous data
192
- - binning_method = "natural_breaks"
193
- - colors = None
194
- - color_ramp = "YlOrRd"
195
- - categorical = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
196
- - base_map = None
197
- - missing_label = None # Add a label for no data
191
+ - `use_bins` = True # If False, the map will be colored by a continuous value
192
+ - `bins` = 5 # Number of bins for continuous data
193
+ - `binning_method` = "natural_breaks"
194
+ - `colors` = None
195
+ - `color_ramp` = "YlOrRd"
196
+ - `categorical` = False # If True, the map will be colored by category. If False, it will be colored by a continuous value
197
+ - `base_map` = None
198
+ - `missing_label` = None # Add a label for no data
198
199
 
199
200
  `basemap` can be `{ISO}-{level}` or `{ISO}|{subset}-{level}`.
200
201
  For example, `se-4` will show Swedish counties, while `se|03-7` will show municipalities (`se-7`) starting with `03`.
@@ -203,6 +204,10 @@ For example, `se-4` will show Swedish counties, while `se|03-7` will show munici
203
204
 
204
205
  _ Inherits from Map _
205
206
 
207
+ **BubbleMap**
208
+
209
+ _ Inherits from Map _
210
+
206
211
  **ProgressChart**
207
212
 
208
213
  **RangePlot**
@@ -247,6 +252,12 @@ Roadmap
247
252
  Changelog
248
253
  ---------
249
254
 
255
+ - 1.61.0
256
+
257
+ - Added non-binned color ramp support to ChoroplethMap, with `use_bins=False`
258
+ - Improved data validation in ChoroplethMap
259
+ - Put largest value on top in choropleth map legends
260
+
250
261
  - 1.60.1
251
262
 
252
263
  - Don't require fiona. Geopandas now support Pyogrio
@@ -9,6 +9,6 @@ python-dateutil<3,>=2
9
9
  Pillow==10.4.0
10
10
  requests>=2.22
11
11
  matplotlib-label-lines==0.5.1
12
- geopandas>1
12
+ geopandas>=1
13
13
  mapclassify==2.6.1
14
- fiona>=1.10
14
+ puremagic>=1
@@ -35,9 +35,9 @@ setup(
35
35
  "Pillow==10.4.0",
36
36
  "requests>=2.22",
37
37
  "matplotlib-label-lines==0.5.1",
38
- "geopandas>1",
38
+ "geopandas>=1",
39
39
  "mapclassify==2.6.1",
40
- "fiona>=1.10",
40
+ "puremagic>=1",
41
41
  ],
42
42
  setup_requires=["flake8"],
43
43
  include_package_data=True,