I'm trying to use plotnine to save a high-resolution png image.
With a test dataset, this looks like:
from plotnine import *
import pandas as pd
import numpy as np
df = pd.DataFrame()
df['x'] = np.arange(0,10,0.01)
df['y'] = np.sin(df['x'])
p = ggplot(df, aes(x='x',y='y')) + labs(x='x', y='y') + geom_point(size=0.1)
p.save(filename = 'test3.png', height=5, width=5, units = 'in', dpi=1000)
This produces a low-resolution .png file containing my plot, which is not improved when I increase the specified dpi.
I've also tried saving with:
ggsave(plot=p, filename='test.png', dpi=1000)
and replacing dpi=1000
with res=1000
. This produces identical low-resolution png files.
How can I save my plot at the resolution I want?
Edit: This bug is resolved in plotnine version 0.3.0. and the above code works correctly.
MatPlotLib with Python To get a high-quality image, we can use . eps image format. You can increase the dot per inch value, i.e., dpi. Using savefig() method, we can save the image locally.
To save the file in pdf format, use savefig() method where the image name is myImagePDF. pdf, format="pdf". We can set the dpi value to get a high-quality image. Using the saving() method, we can save the image with format=”png” and dpi=1200.
Using ggplot in Python allows you to build visualizations incrementally, first focusing on your data and then adding and tuning components to improve its graphical representation. In the next section, you'll learn how to use colors and how to export your visualizations.
To add a title, we include the option ggtitle and include the name of the graph as a string argument.
Since this still isn't answered and I just got directed here, too...
According to @has2k1 (the author of plotnine
), this was a bug and is now resolved. This commit looks like it might be the referenced fix.
To solve the issue, ensure you are using the git version or at least version 0.3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With