newsworthycharts 1.63.5__tar.gz → 1.64.1__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.1}/PKG-INFO +24 -6
  2. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/README.rst +22 -4
  3. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/__init__.py +1 -1
  4. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/categoricalchart.py +32 -0
  5. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/chart.py +26 -13
  6. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/datalist.py +13 -0
  7. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1/newsworthycharts.egg-info}/PKG-INFO +24 -6
  8. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/LICENSE.txt +0 -0
  9. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/MANIFEST.in +0 -0
  10. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/bubblemap.py +0 -0
  11. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/choroplethmap.py +0 -0
  12. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/custom/__init__.py +0 -0
  13. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/custom/climate_cars.py +0 -0
  14. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/datawrapper.py +0 -0
  15. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/__init__.py +0 -0
  16. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/color_fn.py +0 -0
  17. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/colors.py +0 -0
  18. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/formatter.py +0 -0
  19. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/geography.py +0 -0
  20. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/locator.py +0 -0
  21. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/mimetypes.py +0 -0
  22. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/lib/utils.py +0 -0
  23. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/map.py +0 -0
  24. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/maps/se-4.gpkg +0 -0
  25. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/maps/se-7.gpkg +0 -0
  26. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/rangeplot.py +0 -0
  27. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/rc/newsworthy +0 -0
  28. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/scatterplot.py +0 -0
  29. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/seasonalchart.py +0 -0
  30. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/serialchart.py +0 -0
  31. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/storage.py +0 -0
  32. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/stripechart.py +0 -0
  33. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/translations/datawrapper_regions.csv +0 -0
  34. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/translations/regions.py +0 -0
  35. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts/translations/se_municipalities.csv +0 -0
  36. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts.egg-info/SOURCES.txt +0 -0
  37. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts.egg-info/dependency_links.txt +0 -0
  38. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts.egg-info/not-zip-safe +0 -0
  39. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts.egg-info/requires.txt +0 -0
  40. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/newsworthycharts.egg-info/top_level.txt +0 -0
  41. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/setup.cfg +0 -0
  42. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/setup.py +0 -0
  43. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_categorical_chart.py +0 -0
  44. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_choropleth_maps.py +0 -0
  45. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_custom_climate_cars.py +0 -0
  46. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_data_list.py +0 -0
  47. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_datawrapper.py +0 -0
  48. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_main.py +0 -0
  49. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_rangeplot.py +0 -0
  50. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/test/test_scatterplot.py +0 -0
  51. {newsworthycharts-1.63.5 → newsworthycharts-1.64.1}/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.1
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.1.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
 
@@ -213,6 +214,10 @@ _ Inherits from Map _
213
214
 
214
215
  **ProgressChart**
215
216
 
217
+ _ Inherits from CategoricalChart _
218
+
219
+ - `target` = None # A target value to compare to, often 1 (when using percentages)
220
+
216
221
  **RangePlot**
217
222
 
218
223
  **ScatterPlot**
@@ -254,6 +259,19 @@ Roadmap
254
259
  Changelog
255
260
  ---------
256
261
 
262
+ - 1.64.1
263
+
264
+ - Fixed assumption about y axis being the value axis in tick cleaning
265
+ - Fix floating point bug in label handling, causing some integer labels to disappear when decimals=0
266
+
267
+ - 1.64.0
268
+
269
+ - Improved handling of value axis in categorical charts
270
+ - Make sure at least one value axis tick is always printed
271
+ - Experimental support for simple, single series pie charts in CategoricalChart
272
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
273
+ - Fixed weird edge case when ticks would be offset for small numbers
274
+
257
275
  - 1.63.5
258
276
 
259
277
  - 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
 
@@ -186,6 +187,10 @@ _ Inherits from Map _
186
187
 
187
188
  **ProgressChart**
188
189
 
190
+ _ Inherits from CategoricalChart _
191
+
192
+ - `target` = None # A target value to compare to, often 1 (when using percentages)
193
+
189
194
  **RangePlot**
190
195
 
191
196
  **ScatterPlot**
@@ -227,6 +232,19 @@ Roadmap
227
232
  Changelog
228
233
  ---------
229
234
 
235
+ - 1.64.1
236
+
237
+ - Fixed assumption about y axis being the value axis in tick cleaning
238
+ - Fix floating point bug in label handling, causing some integer labels to disappear when decimals=0
239
+
240
+ - 1.64.0
241
+
242
+ - Improved handling of value axis in categorical charts
243
+ - Make sure at least one value axis tick is always printed
244
+ - Experimental support for simple, single series pie charts in CategoricalChart
245
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
246
+ - Fixed weird edge case when ticks would be offset for small numbers
247
+
230
248
  - 1.63.5
231
249
 
232
250
  - 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.1"
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,21 +524,32 @@ 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
+ value_axis = "_y" if self.value_axis == self.ax.yaxis else "_x"
531
+ # remove non integer ticks
532
+ if self.decimals == 0:
533
+ y = [float(getattr(x, value_axis)) for x in ticks]
534
+ if self.units == "percent":
535
+ y = [x for x in y if round(x * 100, 5).is_integer()]
536
+ else:
537
+ y = [x for x in y if round(x, 5).is_integer()]
538
+ self.value_axis.set_ticks(y)
539
+ # Remove duplicate y ticks (most should be gone as per above)
540
+ elif len(ticks_) == 2 and self.data:
529
541
  # When only two ticks we want them on top and bottom
530
- self.value_axis.set_ticks([float(ticks[0]._y), self.data.max_val])
542
+ self.value_axis.set_ticks([float(getattr(ticks[0], value_axis)), self.data.max_val])
531
543
  elif len(ticks_) < len(ticks):
532
- y = [float(x._y) for x in ticks_]
533
- 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()]
544
+ y = [float(getattr(x, value_axis)) for x in ticks_]
538
545
  self.value_axis.set_ticks(y)
539
546
 
547
+ # Force a second tick if we ended up having just one
548
+ ticks = self.value_axis.get_ticklabels()
549
+ ticks_ = [x for (i, x) in enumerate(ticks) if ticks[i - 1].get_text() != x.get_text()]
550
+ if len(ticks_) <= 1 and self.data:
551
+ self.value_axis.set_ticks([0, self.data.max_val])
552
+
540
553
  for a in self.annotations:
541
554
  self._annotate_point(a["text"], a["xy"], a["direction"])
542
555
  if self.ylabel is not None:
@@ -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.1
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.1.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
 
@@ -213,6 +214,10 @@ _ Inherits from Map _
213
214
 
214
215
  **ProgressChart**
215
216
 
217
+ _ Inherits from CategoricalChart _
218
+
219
+ - `target` = None # A target value to compare to, often 1 (when using percentages)
220
+
216
221
  **RangePlot**
217
222
 
218
223
  **ScatterPlot**
@@ -254,6 +259,19 @@ Roadmap
254
259
  Changelog
255
260
  ---------
256
261
 
262
+ - 1.64.1
263
+
264
+ - Fixed assumption about y axis being the value axis in tick cleaning
265
+ - Fix floating point bug in label handling, causing some integer labels to disappear when decimals=0
266
+
267
+ - 1.64.0
268
+
269
+ - Improved handling of value axis in categorical charts
270
+ - Make sure at least one value axis tick is always printed
271
+ - Experimental support for simple, single series pie charts in CategoricalChart
272
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
273
+ - Fixed weird edge case when ticks would be offset for small numbers
274
+
257
275
  - 1.63.5
258
276
 
259
277
  - Improved edge case handling when using fixed decimal places and remove duplicated ticks