You are not logged in.
Recently I am plotting some figures using pyplot. If I save the figure in png format, it has great quality, but not in pdf.
Tried setting the dpi and figure size but doesn't work. Seesm on Ubuntu and Windows I have not this problem. Anybody know why? Thanks. ^_^.
Offline
update.
Last edited by godott (2014-11-29 21:34:36)
Offline
can anybody give a solution? Thanks very much!
Offline
I guess your description is much too vague for people to be able to help you. Can you be more specific? What exactly did you do, what did you expect? In what way is the pdf quality not sufficient? What exactly doesn't work when setting dpi and figure size? What is different in Ubuntu and Windows?
Can you provide a minimal test case that shows your problem (python code, screenshots etc)? I could run such a script, I have matplotlib installed, then we can compare. I'm no master, though, just played around a bit so far.
Right now I can only say: works for me. When I set my script output to pdf, I get a nice vectorized plot inside with, for me, good quality.
Last edited by Sanne (2014-11-30 01:48:29)
If our currency were not money but appreciation and acknowledgement for what we do for others, for the community, for the benefit of all, we would have paradise on earth.
Offline
I guess your description is much too vague for people to be able to help you. Can you be more specific? What exactly did you do, what did you expect? In what way is the pdf quality not sufficient? What exactly doesn't work when setting dpi and figure size? What is different in Ubuntu and Windows?
Can you provide a minimal test case that shows your problem (python code, screenshots etc)? I could run such a script, I have matplotlib installed, then we can compare. I'm no master, though, just played around a bit so far.
Right now I can only say: works for me. When I set my script output to pdf, I get a nice vectorized plot inside with, for me, good quality.
Thanks very much for your reply!
I use the standard Python 3 comes with Arch Linux(If I use python2 in virtualenv, matplotlib will have some backend problem). The code for plotting is also pretty standard:
import matplotlib.pyplt as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.loglog(x_data, y_data)
ax.fill_between(x_data, y_data1,y_data2)
plt.show()
fig.savefig("result.pdf", format="pdf", dpi=600)
Either I save the figure when the it shows or by "savefig", the pdf picture is not giving me a good quality one like png is. I don't know what could be the problem.
Thanks.
Offline
For me it also works fine. I tried with and without the dpi setting. I see no difference. I think, because a vector image is created with pdf the dpi setting would normally be ignored, unless there is a bitmap embedded.
Offline
godott, your example doesn't run for me, you didn't define x_data, y_data, y_data2:
Traceback (most recent call last):
NameError: name 'x_data' is not defined
Can you give a working example that runs as it is, and best also a screenshot of the bad pdf output you're seeing?
About the dpi setting, I think FreeTheBee is correct, as vector data is dpi independent.
Another shot in the dark: what about your optional dependencies on matplotlib? Maybe there's something missing. Check with
$ pacman -Qi python-matplotlib
Here's what I have:
Optional Deps : python-gobject: for GTK3Agg/GTK3Cairo backend
python-cairo: for GTK3Cairo backend [installed]
python-pyqt4: for Qt4Agg backend [installed]
tk: used by the TkAgg backend [installed]
ghostscript: usetex dependencies [installed]
texlive-bin: usetex dependencies
python-tornado: for webagg backend [installed]
python-pillow: for reading/saving .jpg/bmp/tiff files [installed]
If our currency were not money but appreciation and acknowledgement for what we do for others, for the community, for the benefit of all, we would have paradise on earth.
Offline
godott, your example doesn't run for me, you didn't define x_data, y_data, y_data2:
Traceback (most recent call last): NameError: name 'x_data' is not defined
Can you give a working example that runs as it is, and best also a screenshot of the bad pdf output you're seeing?
About the dpi setting, I think FreeTheBee is correct, as vector data is dpi independent.
Another shot in the dark: what about your optional dependencies on matplotlib? Maybe there's something missing. Check with
$ pacman -Qi python-matplotlib
Here's what I have:
Optional Deps : python-gobject: for GTK3Agg/GTK3Cairo backend python-cairo: for GTK3Cairo backend [installed] python-pyqt4: for Qt4Agg backend [installed] tk: used by the TkAgg backend [installed] ghostscript: usetex dependencies [installed] texlive-bin: usetex dependencies python-tornado: for webagg backend [installed] python-pillow: for reading/saving .jpg/bmp/tiff files [installed]
for x_data, y_data you can do
x_data=numpy.linspace(0, 1, 100)
y_data=numpy.sin(x_data)
y_data1=y_data
y_data2=y_data-1
I installed matplotlib from pip originally. Now I reinstalled it using pacman and have all the dependancies installed. I still have the problem. Especially when I do "fill_between". I will update the comparison of the result of pdf and png. There is big difference.
https://www.dropbox.com/s/u95y0ohr10lw9 … 5.pdf?dl=0
https://www.dropbox.com/s/txgk3k8jk9hey … 5.png?dl=0
Last edited by godott (2014-12-01 21:10:14)
Offline
Now I see. The problem could be the image viewer. I used both mupdf and xnviewmp to view the generated pdf file. But they both give me bad quality especially when "fill_between". Now if I open with dropbox viewer the figure seems fine. I will try to figure it out.
Thanks @Sanne @FreeTheBee!
BTW what image viewer do you guys use?
Last edited by godott (2014-12-01 21:14:41)
Offline
Ah, the viewer. Should have thought about that. I usually use Okular, renders fine. Xpdf and ePDFViewer also. Zathura and Mupdf, however, show a white gap between the filling and the border. Is that what you mean?
So the problem seems to be the viewer then. Good to know there are differences.
Last edited by Sanne (2014-12-01 21:45:46)
If our currency were not money but appreciation and acknowledgement for what we do for others, for the community, for the benefit of all, we would have paradise on earth.
Offline
Same for me, just checked with mupdf. I usually use evince or acroread (although it is time to replace the latter).
Offline
So is this issue solved now? If so, godott, would you please mark the thread as solved?
If our currency were not money but appreciation and acknowledgement for what we do for others, for the community, for the benefit of all, we would have paradise on earth.
Offline