New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No transparency in *.pgf file when using pgf Backend. #5867
Comments
CC @pwuertz Can you provide a minimal example that triggers the issue |
Hi the following code produces transparency in the *.pdf, but when i compile the *.pgf using pdflatex this transparency is gone... (there is a possibility i am using latex wrong, but the *.pgf file contains no sign of transparencies...) import numpy as np
import matplotlib as mpl
mpl.use('pgf')
import matplotlib.pyplot as plt
pgf_with_latex = { # setup matplotlib to use latex for output
"pgf.texsystem": "pdflatex", # change this if using xetex or lautex
"text.usetex": True, # use LaTeX to write all text
"pgf.preamble": [
r"\usepackage[utf8x]{inputenc}", # use utf8 fonts becasue your computer can handle it :)
r"\usepackage[T1]{fontenc}", # plots will be generated using this preamble
]
}
mpl.rcParams.update(pgf_with_latex)
def savefig(filename):
plt.savefig('{}.pgf'.format(filename), transparent=True)
plt.savefig('{}.pdf'.format(filename))
plt.savefig('{}.png'.format(filename))
x = np.linspace(0,10, num = 10)
y1 = 1*x
y2 = 0.2*x + 4
plt.fill_between(x,0,y1,color='red',alpha=0.5)
plt.fill_between(x,0,y2,color='blue',alpha=0.5)
#plt.show()
savefig("test") |
Thanks, I edited your example to correctly render the code |
You were faster than me ;-) i had to look up how to format it... |
If the PDF/PNG files generated by the backend are correct it is safe to assume that the generated PGF code and your TeX installation are fine. When you compile your TeX document and the pgf code, are you using some kind of IDE with an integrated PDF viewer that might have issues rendering transparent objects? Other then that I guess there are always ways to break latex by combining various modules in the preamble. You could try compiling a minimal document just to be sure. Btw, according to the documentation |
You sir are correct. I was using texstudio on windows and the internal PDF viewer did not show the transparency... What I find very odd is that when i include the *.pdf it would render correctly even in texstudio. But thank you very much for the help. This one took me a long time to figure out. I apologize that this turned out not to be a problem with matplotlib afterall. |
Not a problem. We all learned something new. Closing. |
Ummm. Sorry to do this, but I must have made a mistake when viewing that one pdf. It still seems to me that in all pdf documents I have opened the file, transparency does not come through. This issue should be reopened... :-( |
If you dump the .pgf file somewhere I'll have a look at it. First I'd like to confirm that the problem is not the pgf code generated by matplotlib. |
Hi Pwuertz, i pasted the contents of the pgf created by the testscript here: I can't read it very well myself, but find no hint of transparency in it... |
The pgf commands
|
Yes. In the minimal latex document transparency is fine. It even shows up in texstudio, so it must be one of the other packages which i am loading... there are many so it will take me a while to pin down which one it is. PGF version is 3.0 |
You're not going to like this... apparently I was using a package named transparent... (god knows for what) The great help that i have receives has prompted me to make a small donation to matplotlib, so I guess at least some good as come of this. Thanks for the great support. |
Oh well, latex can be a real mess when it comes to interoperability of modules. Or understanding what a module actually does :). But it's good to know that the fix for your problem was rather simple in the end. |
I seem to run into this problem when using the *.pgf backend. Both the pdf and png files show the transparency correctly, but the *.pgf file does not.
The text was updated successfully, but these errors were encountered: