6

I'm building a simulation tool in python that outputs a number of plots using plotnine. However, for each individual plot I save, I get the following error messages:

C:\Users\tarca\Anaconda3\lib\site-packages\plotnine\ggplot.py:706: UserWarning: Saving 10 x 3 in image.
  from_inches(height, units), units))

C:\Users\tarca\Anaconda3\lib\site-packages\plotnine\ggplot.py:707: UserWarning: Filename: my_plot.png
  warn('Filename: {}'.format(filename))

I've already tried manually setting all of the arguments, and I've tried saving the files using both plot.save() and ggsave() - both yield the same result. If you search the error, the only thing that comes up is that the author of the following tutorial gets the same errors, though they are not addressed therein:

https://monashdatafluency.github.io/python-workshop-base/modules/plotting_with_ggplot/

To save the plots, I'm using code similar to:

plot.save(filename = 'my_plot.png', width = 10, height = 3, dpi = 300)

I'm hoping to be able to save the plots without generating any annoying messages that may confuse anyone using the program.

2 Answers2

3

I'm not sure why this warning is still displayed in the tutorial you linked to, because as soon as I do

import warnings
warnings.filterwarnings('ignore')

as described there right at the beginning, too, the UserWarning which was printed before when saving a plot to disk is successfully suppressed.

SpghttCd
  • 10,510
  • 2
  • 20
  • 25
  • 1
    Yeah, that works for me too, but it suppresses all warnings - including ones that may be important. For the time being I'm turning warnings off and on before and after plotting, though I wish plotnine would resolve this as I'm not sure the purpose/value of the warnings. – Arcadius Fox Apr 24 '19 at 22:05
2

Yes there is, just use:

fig2.save(fig_dir + "/figure2.png", width = w, height = h, verbose = False)

If you don't specify verbose = plotnine will always display a warning. See their GitHub module why.

Jordy
  • 43
  • 1
  • 5