diff --git a/CHANGES.rst b/CHANGES.rst index 450b6e45..e130c4a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,7 @@ in progress - [docs] Refactor "decoders" section to "integrations", and improve index/overview page - [export] Improve export capabilities by adding parameters ``sort``, ``direction``, ``limit``, and ``scalar``. Thanks, @ClemensGruber. +- [export] Repair ``ggplot`` graph rendering by switching to ``plotnine`` .. _kotori-0.27.0: diff --git a/kotori/io/export/plot.py b/kotori/io/export/plot.py index c1127b3b..6ed7792c 100644 --- a/kotori/io/export/plot.py +++ b/kotori/io/export/plot.py @@ -171,18 +171,28 @@ def render_png(self, buffer): """ - elif renderer == 'ggplot': - - # https://yhat.github.io/ggplot/notebook.html?page=build/docs/examples/Multiple%20Line%20Plot.html - # https://stackoverflow.com/questions/23541497/is-there-a-way-to-plot-a-pandas-series-in-ggplot - # https://stackoverflow.com/questions/24478925/is-it-possible-to-plot-multiline-chart-on-python-ggplot/24479513#24479513 - - # https://github.com/yhat/ggplot/blob/master/docs/how-to/Building%20Faceted%20(or%20Trellised)%20Plots.ipynb - # https://github.com/yhat/ggplot/blob/master/docs/how-to/Annotating%20Plots%20-%20Titles%20and%20Labels.ipynb - # https://github.com/yhat/ggplot/blob/master/docs/how-to/How%20to%20make%20xkcd%20style%20graphs.ipynb + elif renderer in ['ggplot', 'plotnine']: + """ + Renderer based on ggplot, now in plotnine. + + ggplot + ====== + - https://yhat.github.io/ggplot/notebook.html?page=build/docs/examples/Multiple%20Line%20Plot.html + - https://stackoverflow.com/questions/23541497/is-there-a-way-to-plot-a-pandas-series-in-ggplot + - https://stackoverflow.com/questions/24478925/is-it-possible-to-plot-multiline-chart-on-python-ggplot/24479513#24479513 + + - https://github.com/yhat/ggplot/blob/master/docs/how-to/Building%20Faceted%20(or%20Trellised)%20Plots.ipynb + - https://github.com/yhat/ggplot/blob/master/docs/how-to/Annotating%20Plots%20-%20Titles%20and%20Labels.ipynb + - https://github.com/yhat/ggplot/blob/master/docs/how-to/How%20to%20make%20xkcd%20style%20graphs.ipynb + + plotnine + ======== + - https://github.com/has2k1/plotnine + - https://plotnine.readthedocs.io/ + """ - from ggplot import ggplot, aes, qplot, geom_line, geom_text, ggtitle, stat_smooth, scale_x_date, date_format, date_breaks - from ggplot import theme_538, theme_bw, theme_gray, theme_xkcd + from plotnine import ggplot, aes, qplot, geom_line, geom_text, ggtitle, stat_smooth, scale_x_datetime + from plotnine import theme_538, theme_bw, theme_gray, theme_xkcd # https://stackoverflow.com/questions/24478925/is-it-possible-to-plot-multiline-chart-on-python-ggplot/24479513#24479513 # https://stackoverflow.com/questions/23541497/is-there-a-way-to-plot-a-pandas-series-in-ggplot @@ -196,9 +206,12 @@ def render_png(self, buffer): plot = ggplot(df, aes(x='time', y='value', color='variable'))\ + geom_line()\ - + scale_x_date(limits=(datetime_min, datetime_max), breaks=locator, labels=formatter)\ + + scale_x_datetime(limits=(datetime_min, datetime_max))\ + ggtitle(bucket.title.human) + # FIXME: Currently croaks. + # + scale_x_date(limits=(datetime_min, datetime_max), breaks=locator, labels=formatter) \ + # Axis labels plot.xlab = 'Time' plot.ylab = 'Value' diff --git a/setup.py b/setup.py index 97a053fc..3697914f 100644 --- a/setup.py +++ b/setup.py @@ -124,7 +124,7 @@ # Algorithms # ---------- #'scipy>=1.4.1,<1.6', - 'ggplot>=0.11.5,<0.12', + 'plotnine<0.13', # gfortran # aptitude install libatlas-base-dev lapack-dev gfortran or diff --git a/test/test_export.py b/test/test_export.py index c4a89b2a..be749574 100644 --- a/test/test_export.py +++ b/test/test_export.py @@ -246,3 +246,58 @@ def test_export_hdf5(machinery, create_influxdb, reset_influxdb): assert hdf["/itest_foo_bar/table"][()] == array( [(1583810982000000000, 51.8, 25.26)], dtype=[('index', '