-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pcolormesh with shading=gouraud gives error when saved as eps #16217
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
Comments
I provide an example. The first figure (etaGainH.png) is the one I save from python with plt.savefig('etaGainH.png'). The second figure is the one I get when I use plt.savefig('etaGainH.eps'). This is the code I'm using: fig, ax = plt.subplots(1,1,figsize=(5.3,4.3))
X,Y = np.meshgrid(hstar,invparam,indexing='ij')
cmap = mpl.cm.get_cmap('viridis') ;\
plt.pcolormesh(X,Y,etaGain*100,cmap=cmap,shading='gouraud');\
cbar = plt.colorbar()
cbar.set_label(r'$\mathcal{G}_{\eta}\;[\%]$',fontsize = 14)
plt.ylim([0.5,1.5])
plt.xlim([0.16,0.4])
plt.savefig('etaGainH.eps',format='eps',bbox_inches='tight',dpi=300) Note that if I use shading='flat' instead of shading='gouraud', this is what I get
Code fig, ax = plt.subplots(1,1,figsize=(5.3,4.3))
X,Y = np.meshgrid(hstar,invparam,indexing='ij')
cmap = mpl.cm.get_cmap('viridis') ;\
plt.pcolormesh(X,Y,etaGain*100,cmap=cmap,shading='flat');\
cbar = plt.colorbar()
cbar.set_label(r'$\mathcal{G}_{\eta}\;[\%]$',fontsize = 14)
plt.ylim([0.5,1.5])
plt.xlim([0.16,0.4])
plt.savefig('etaGainH.eps',format='eps',bbox_inches='tight',dpi=300) The problem seems to be related to this particular shading option. |
Locally this works for me, and #1993 suggests that it indeed should. |
Hi, thank you for your reply. import matplotlib.pyplot as plt
import numpy as np
plt.pcolormesh(np.random.randn(10,10), shading='gouraud')
plt.gcf().savefig('test.eps') works fine. However, when I save the image with .eps, some pixels change. You can see the difference in my second post. This problem does not exist when I use shading='flat' or when I save the image as .png. |
Your example is not reproducible: we don't have the hstar, invparam variables. |
I'm sorry, you are right. For images with shading='gouraud': import matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,25)
y = np.linspace(0,1,25)
X,Y = np.meshgrid(x,y,indexing='ij')
z = np.sin(X*2*np.pi) + np.cos(Y*2*np.pi)
cmap = plt.get_cmap('viridis')
plt.subplots(1,1,figsize=(5.3,4.3))
plt.pcolormesh(x, y, z, cmap=cmap, shading='gouraud')
cbar = plt.colorbar()
plt.title('Gouraud')
plt.savefig('TestGou.eps',bbox_inches='tight',dpi=300) Output: For images with shading='flat': import matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,25)
y = np.linspace(0,1,25)
X,Y = np.meshgrid(x,y,indexing='ij')
z = np.sin(X*2*np.pi) + np.cos(Y*2*np.pi)
cmap = plt.get_cmap('viridis')
plt.subplots(1,1,figsize=(5.3,4.3))
plt.pcolormesh(x, y, z, cmap=cmap, shading='flat')
cbar = plt.colorbar()
plt.title('Flat')
plt.savefig('TestFlat.eps',bbox_inches='tight',dpi=300) Output: If you compare the image TestGou.png and TestGou-eps-converted-to.pdf, they are different. On the other hand, TestFlat-eps-converted-to.pdf and TestFlat.png are identical. |
Yes, I can confirm the difference now. |
I'm not sure of the exact portion of the change that did it, but this was fixed by #23294. |
Bug summary
I have a pcolormesh that has shading='gouraud', and I am trying to save it to an .eps. If I save the image as .png everything works fine, but when I save it as .eps it gives error. A similar issue was already open and then closed in the past.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
plt.pcolormesh(np.random.randn(10,10), shading='gouraud')
plt.gcf().savefig('test.eps')
Matplotlib version
matplotlib 3.1.1
Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
The text was updated successfully, but these errors were encountered: