newsworthycharts 1.63.5__tar.gz → 1.64.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.63.5/newsworthycharts.egg-info → newsworthycharts-1.64.0}/PKG-INFO +15 -6
  2. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/README.rst +13 -4
  3. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/__init__.py +1 -1
  4. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/categoricalchart.py +32 -0
  5. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/chart.py +23 -11
  6. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/datalist.py +13 -0
  7. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0/newsworthycharts.egg-info}/PKG-INFO +15 -6
  8. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/LICENSE.txt +0 -0
  9. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/MANIFEST.in +0 -0
  10. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/bubblemap.py +0 -0
  11. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/choroplethmap.py +0 -0
  12. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/custom/__init__.py +0 -0
  13. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/custom/climate_cars.py +0 -0
  14. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/datawrapper.py +0 -0
  15. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/__init__.py +0 -0
  16. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/color_fn.py +0 -0
  17. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/colors.py +0 -0
  18. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/formatter.py +0 -0
  19. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/geography.py +0 -0
  20. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/locator.py +0 -0
  21. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/mimetypes.py +0 -0
  22. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/lib/utils.py +0 -0
  23. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/map.py +0 -0
  24. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/maps/se-4.gpkg +0 -0
  25. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/maps/se-7.gpkg +0 -0
  26. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/rangeplot.py +0 -0
  27. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/rc/newsworthy +0 -0
  28. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/scatterplot.py +0 -0
  29. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/seasonalchart.py +0 -0
  30. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/serialchart.py +0 -0
  31. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/storage.py +0 -0
  32. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/stripechart.py +0 -0
  33. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/translations/datawrapper_regions.csv +0 -0
  34. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/translations/regions.py +0 -0
  35. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts/translations/se_municipalities.csv +0 -0
  36. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts.egg-info/SOURCES.txt +0 -0
  37. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts.egg-info/dependency_links.txt +0 -0
  38. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts.egg-info/not-zip-safe +0 -0
  39. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts.egg-info/requires.txt +0 -0
  40. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/newsworthycharts.egg-info/top_level.txt +0 -0
  41. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/setup.cfg +0 -0
  42. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/setup.py +0 -0
  43. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_categorical_chart.py +0 -0
  44. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_choropleth_maps.py +0 -0
  45. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_custom_climate_cars.py +0 -0
  46. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_data_list.py +0 -0
  47. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_datawrapper.py +0 -0
  48. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_main.py +0 -0
  49. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_rangeplot.py +0 -0
  50. {newsworthycharts-1.63.5 → newsworthycharts-1.64.0}/test/test_scatterplot.py +0 -0
  51. {newsworthycharts-1.63.5 → newsworthycharts-1.64.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.63.5
3
+ Version: 1.64.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.63.5.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.64.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
@@ -154,7 +154,7 @@ These settings are available for all chart types:
154
154
 
155
155
  **SerialChart**
156
156
 
157
- - type = 'line' # line|bars
157
+ - type = 'line' # line|bars, or a list of types for each data serie
158
158
  - bar_width = 0.9 # percent of data point width
159
159
  - allow_broken_y_axis = True|False # default depends on chart type
160
160
  - baseline = 0 # The “zero” line. Useful for plotting deviations, e.g. temperatures above/below mean
@@ -181,11 +181,12 @@ _ Inherits from SerialChart _
181
181
 
182
182
  **CategoricalChart**
183
183
 
184
- - bar_orientation = "horizontal" # [horizontal|vertical]
185
184
  - annotation_rotation = 0
186
- - stacked = False
187
- - legend = True
185
+ - bar_orientation = "horizontal" # [horizontal|vertical]
188
186
  - colors = None # A dictionary of colors
187
+ - legend = True
188
+ - stacked = False
189
+ - type = "bars" # [bars|pie]
189
190
 
190
191
  **CategoricalChartWithReference**
191
192
 
@@ -254,6 +255,14 @@ Roadmap
254
255
  Changelog
255
256
  ---------
256
257
 
258
+ - 1.64.0
259
+
260
+ - Improved handling of value axis in categorical charts
261
+ - Make sure at least one value axis tick is always printed
262
+ - Experimental support for simple, single series pie charts in CategoricalChart
263
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
264
+ - Fixed weird edge case when ticks would be offset for small numbers
265
+
257
266
  - 1.63.5
258
267
 
259
268
  - Improved edge case handling when using fixed decimal places and remove duplicated ticks
@@ -127,7 +127,7 @@ These settings are available for all chart types:
127
127
 
128
128
  **SerialChart**
129
129
 
130
- - type = 'line' # line|bars
130
+ - type = 'line' # line|bars, or a list of types for each data serie
131
131
  - bar_width = 0.9 # percent of data point width
132
132
  - allow_broken_y_axis = True|False # default depends on chart type
133
133
  - baseline = 0 # The “zero” line. Useful for plotting deviations, e.g. temperatures above/below mean
@@ -154,11 +154,12 @@ _ Inherits from SerialChart _
154
154
 
155
155
  **CategoricalChart**
156
156
 
157
- - bar_orientation = "horizontal" # [horizontal|vertical]
158
157
  - annotation_rotation = 0
159
- - stacked = False
160
- - legend = True
158
+ - bar_orientation = "horizontal" # [horizontal|vertical]
161
159
  - colors = None # A dictionary of colors
160
+ - legend = True
161
+ - stacked = False
162
+ - type = "bars" # [bars|pie]
162
163
 
163
164
  **CategoricalChartWithReference**
164
165
 
@@ -227,6 +228,14 @@ Roadmap
227
228
  Changelog
228
229
  ---------
229
230
 
231
+ - 1.64.0
232
+
233
+ - Improved handling of value axis in categorical charts
234
+ - Make sure at least one value axis tick is always printed
235
+ - Experimental support for simple, single series pie charts in CategoricalChart
236
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
237
+ - Fixed weird edge case when ticks would be offset for small numbers
238
+
230
239
  - 1.63.5
231
240
 
232
241
  - Improved edge case handling when using fixed decimal places and remove duplicated ticks
@@ -1,4 +1,4 @@
1
- __version__ = "1.63.5"
1
+ __version__ = "1.64.0"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -15,11 +15,43 @@ class CategoricalChart(Chart):
15
15
  self.annotation_rotation = 0
16
16
  self.stacked = False
17
17
  self.legend = True
18
+ self.type = "bars"
18
19
 
19
20
  # Optional: specify a list of colors (for multiple datasets)
20
21
  self.colors = None
21
22
 
23
+ def _add_pie_data(self):
24
+ if len(self.data) > 1:
25
+ raise ValueError("Pie chart takes one data series only.")
26
+ self.legend = False
27
+ self.show_ticks = False
28
+
29
+ data = self.data[0]
30
+ values = [to_float(x[1]) for x in data]
31
+ labels = [x[0] for x in data]
32
+
33
+ if self.colors is not None:
34
+ colors = self.colors
35
+ else:
36
+ colors = [self._nwc_style["qualitative_colors"][i] for i in range(len(values))]
37
+
38
+ explode = [0.1 if x == self.highlight else 0 for x in labels]
39
+
40
+ self.ax.pie(
41
+ values,
42
+ labels=labels,
43
+ startangle=90,
44
+ colors=colors,
45
+ explode=explode
46
+ )
47
+ self.ax.axis('equal')
48
+
49
+ self._setup_legend()
50
+
22
51
  def _add_data(self):
52
+ if self.type == "pie":
53
+ self._add_pie_data()
54
+ return
23
55
  allowed_orientations = ["horizontal", "vertical"]
24
56
  if self.bar_orientation not in allowed_orientations:
25
57
  raise ValueError(f"Valid oriantations: {allowed_orientations}")
@@ -138,10 +138,12 @@ class Chart(object):
138
138
  return self._get_formatter(self.units)
139
139
 
140
140
  def _get_formatter(self, units):
141
- formatter = Formatter(self._language,
142
- decimals=self.decimals,
143
- force_decimals=self.force_decimals,
144
- scale="celsius")
141
+ formatter = Formatter(
142
+ self._language,
143
+ decimals=self.decimals,
144
+ force_decimals=self.force_decimals,
145
+ scale="celsius",
146
+ )
145
147
  if units == "percent":
146
148
  return FuncFormatter(formatter.percent)
147
149
  elif units == "degrees":
@@ -522,20 +524,30 @@ class Chart(object):
522
524
  if try_dec > 2:
523
525
  keep_trying = False
524
526
  try_dec += 1
525
- # Remove duplicate y ticks (most should be gone as per above)
527
+
526
528
  ticks = self.value_axis.get_ticklabels()
527
529
  ticks_ = [x for (i, x) in enumerate(ticks) if ticks[i - 1].get_text() != x.get_text()]
528
- if len(ticks_) == 2 and self.data and self.data.max_val:
530
+ # remove non integer ticks
531
+ if self.decimals == 0:
532
+ y = [float(x._y) for x in ticks]
533
+ if self.units == "percent":
534
+ y = [x for x in y if (x * 100).is_integer()]
535
+ else:
536
+ y = [x for x in y if x.is_integer()]
537
+ self.value_axis.set_ticks(y)
538
+ # Remove duplicate y ticks (most should be gone as per above)
539
+ elif len(ticks_) == 2 and self.data:
529
540
  # When only two ticks we want them on top and bottom
530
541
  self.value_axis.set_ticks([float(ticks[0]._y), self.data.max_val])
531
542
  elif len(ticks_) < len(ticks):
532
543
  y = [float(x._y) for x in ticks_]
533
544
  self.value_axis.set_ticks(y)
534
- elif self.decimals == 0:
535
- # remove non integer ticks
536
- y = [float(x._y) for x in ticks]
537
- y = [x for x in y if x.is_integer()]
538
- self.value_axis.set_ticks(y)
545
+
546
+ # Force a second tick if we ended up having just one
547
+ ticks = self.value_axis.get_ticklabels()
548
+ ticks_ = [x for (i, x) in enumerate(ticks) if ticks[i - 1].get_text() != x.get_text()]
549
+ if len(ticks_) <= 1 and self.data:
550
+ self.value_axis.set_ticks([0, self.data.max_val])
539
551
 
540
552
  for a in self.annotations:
541
553
  self._annotate_point(a["text"], a["xy"], a["direction"])
@@ -171,8 +171,19 @@ class DataSet(MutableSequence):
171
171
 
172
172
  def __init__(self, *args):
173
173
  self.list = list()
174
+ self.min_val = inf
175
+ self.max_val = -inf
174
176
  self.extend(list(args))
175
177
 
178
+ def check(self, v):
179
+ # Update metadata with newly added data
180
+ values = [to_float(x[1]) for x in v]
181
+ values = [x for x in values if x is not None]
182
+ if values:
183
+ self.min_val = min(self.min_val, min(values))
184
+ self.max_val = max(self.max_val, max(values))
185
+ return v
186
+
176
187
  def __len__(self):
177
188
  return len(self.list)
178
189
 
@@ -183,9 +194,11 @@ class DataSet(MutableSequence):
183
194
  del self.list[i]
184
195
 
185
196
  def __setitem__(self, i, v):
197
+ v = self.check(v)
186
198
  self.list[i] = v
187
199
 
188
200
  def insert(self, i, v):
201
+ v = self.check(v)
189
202
  self.list.insert(i, v)
190
203
 
191
204
  def __str__(self):
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.63.5
3
+ Version: 1.64.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.63.5.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.64.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
@@ -154,7 +154,7 @@ These settings are available for all chart types:
154
154
 
155
155
  **SerialChart**
156
156
 
157
- - type = 'line' # line|bars
157
+ - type = 'line' # line|bars, or a list of types for each data serie
158
158
  - bar_width = 0.9 # percent of data point width
159
159
  - allow_broken_y_axis = True|False # default depends on chart type
160
160
  - baseline = 0 # The “zero” line. Useful for plotting deviations, e.g. temperatures above/below mean
@@ -181,11 +181,12 @@ _ Inherits from SerialChart _
181
181
 
182
182
  **CategoricalChart**
183
183
 
184
- - bar_orientation = "horizontal" # [horizontal|vertical]
185
184
  - annotation_rotation = 0
186
- - stacked = False
187
- - legend = True
185
+ - bar_orientation = "horizontal" # [horizontal|vertical]
188
186
  - colors = None # A dictionary of colors
187
+ - legend = True
188
+ - stacked = False
189
+ - type = "bars" # [bars|pie]
189
190
 
190
191
  **CategoricalChartWithReference**
191
192
 
@@ -254,6 +255,14 @@ Roadmap
254
255
  Changelog
255
256
  ---------
256
257
 
258
+ - 1.64.0
259
+
260
+ - Improved handling of value axis in categorical charts
261
+ - Make sure at least one value axis tick is always printed
262
+ - Experimental support for simple, single series pie charts in CategoricalChart
263
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
264
+ - Fixed weird edge case when ticks would be offset for small numbers
265
+
257
266
  - 1.63.5
258
267
 
259
268
  - Improved edge case handling when using fixed decimal places and remove duplicated ticks