Create charts and publish on Amazon S3.
This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
It is written and maintained for Newsworthy, but could possibly come in handy for other people as well.
pip install newsworthycharts
This module comes with two classes, Chart and Storage (and it’s subclasses). When using the Chart class, the generated chart will be saved as a local file:
from newsworthycharts import SerialChart as Chart c = Chart(600, 800) c.title = "Number of smiles per second" c.xlabel = "Time" c.ylabel = "Smiles" c.caption = "Source: Ministry of smiles." data_serie_1 = [("2008-01-01", 6.1), ("2009-01-01", 5.9), ("2010-01-01", 6.8)] c.data.append(data_serie_1) c.highlight = "2010-01-01" c.render("test", "png")
You can use a _storage_ object to save file to a specific location or cloud service:
from newsworthycharts import Chart from newsworthycharts import S3Storage s3 = S3Storage("my_bucket") c = Chart(600, 800, storage=s3) c.title = "Number of smiles per second" c.subtitle = "This chart tells you something very important." c.xlabel = "Time" c.ylabel = "Smiles" c.note = "There are some missing smiles in data" c.caption = "Source: Ministry of smiles." c.render("test", "png")
To store a file in a local folder, use the LocalStorage class:
from newsworthycharts import LocalStorage storage = LocalStorage("/path/to/generated/charts")
Charts are styled using built-in or user-defined styles:
from newsworthycharts import Chart # This chart has the newsworthy default style c = Chart(600, 800, style="newsworthy") # Style can also be the path to a style file (absolute or relative to current working directory) c2 = Chart(600, 800, style="path/to/styles/mystyle.mplstyle")
To set up you own style, copy the build-in default: <https://github.com/jplusplus/newsworthycharts/blob/master/newsworthycharts/rc/newsworthy>
Newsworthycharts will look first among the predefined style files for the requested style, so if you have a custom style file in you working directory you need to give it a unique name not already in use.
To run tests:
python3 -m flake8 python3 -m pytest
To deploy a new version to PyPi:
- Update Changelog below.
- Update version.py
- Build: python3 setup.py sdist bdist_wheel
- Upload: python3 -m twine upload dist/newsworthycharts-X.Y.X*
…assuming you have Twine installed (pip install twine) and configured.
- Introduces subtitle and note.
- Updates default styles to align with Newsworthy style guide.
- Fit footer by logo height. Fixes bug that caused axis overlag when logo was large.
- Introduces stacked categorical bar charts
- Bug fix: Remove failing attemt to store chart in dw format
- Corrects zorder and centers tick on CategoricalChartWithReference
- Introduces new chart: CategoricalChartWithReference
- Fixes bad X ticks in weekly SerialChart (and charts that don’t start in January).
- Add annotation_rotation option to categorical charts
- Fix a crash in some special cases with serial charts shorter than a year.
- Fix a bug where diff between series was not highlighted if one value was close to zero.
- Include translations in build.
- Translates region to Datawrapper standard when making maps.
- Allows list of dicts to be passed to DatawrapperChart to be make tables, categorical maps etc.
- Require requests.
- Bug fixes.
- Introduces Datawrapper Chart type.
- Adds ymax argument (to SerialChart)
- Bug fix: Handle missing values in SerialChart with line.
- Bug fix: Set y max to stacked max in stacked bar chart.
- Introduces stacked bars to SerialChart.
- Fixes bar_orientation bug with init_from()
- Fix an ugly bug where type=line would not work with init_from()
- Some cosmetic changes: no legend if only one series, color updates, thinner zero line.
- Make title and units work with init_from again
- Add warm/cold color function
- Really, really make init_from work, by allowingly allowing allowed attributes
- Fix bug where init_from would sometime duplicate data.
- Make sure init_from does not overwrite class methods.
- Protect private properties from being overwritten by init_from
- When units is count, decimal should default to 0 if not provided. This sometimes didn’t work. Now it does.
- Make init_from work as expected with a language argument
- Make init_from work as expected with multiple data series
- Added a factory method to create charts from a JSON-like Python object, like so: SerialChart.init_from(config, storage)
- Fix packaging error in 1.5.0
- Expose available chart engines in CHART_ENGINES constant for dynamic loading
- Add color_fn property, for coloring bars based on value
- Increase line width in default style
- Upgrading Numpy could potentially affect how infinity is treated in serial charts.
- Revert text adjusting for categorical charts, as it had issues
- Add new ScatterPlot chart class
- Improved text adjusting in serial charts
- More secure YAML file parsing
- Make small bar charts with very many bars look better
- Make labels work again, 1.3.1 broke those in some circumstances
- Make inner_max/min_x work with leading / trailing None values
- Make sure single, orphaned values are visible (as points) in line charts
- Allow (and recommend) using Matplotlib 3. This may affect how some charts are rendered.
- Removed undocumented and incomplete Latex support from caption.
- Don’t highlight diff outside either series’ extreme ends.
- Use strong color if there is nothing to highlight.
- Fix a bug where decimals setting was not used in all annotations. Potentially breaking in some implementations.
- Make the annotation offset 80% of the fontsize (used to be a hardcoded number of pixels)
- Small cosmetic update: Decrease offset of annotation.
- Require Matplotlib < 3, because we are still relying on some features that are deprecated there. Also, internal changes to Matplot lib may cause some charts to look different depending on version.
- Make annotation use default font size, as relative sizing didn’t work here anyway
- Move class properties to method properties to make sure multiple Chart instances work as intended/documented. This will make tests run again.
- None values in bar charts are not annotated (trying to annotate None values used to result in a crash)
- More tests
- Annotations should now work as expected on series with missing data
- Fix bug where decimal setting wasn’t always respected
- Make no decimals the default if unit is “count”
- First version
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for newsworthycharts-1.13.0-py3-none-any.whl