FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

pcolormesh with shading=gouraud gives error when saved as eps · Issue #16217 · matplotlib/matplotlib · GitHub

Repository navigation

pcolormesh with shading=gouraud gives error when saved as eps #16217

Closed

Description

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)]

Activity

  1. lclanzi commented on Jan 14, 2020

    Author

    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').


    etaGainH-eps-converted-to.pdf

    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


    etaGainHFlat-eps-converted-to.pdf

    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.
    Hope that the issue is more clear.

  2. anntzer commented on Jan 14, 2020

    Contributor

    Locally this works for me, and #1993 suggests that it indeed should.

  3. lclanzi commented on Jan 14, 2020

    Author

    Hi, thank you for your reply.
    I did not explain well what the problem is in the first post.
    The code

    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.

  4. anntzer commented on Jan 14, 2020

    Contributor

    Your example is not reproducible: we don't have the hstar, invparam variables.

  5. lclanzi commented on Jan 14, 2020

    Author

    I'm sorry, you are right.
    Here it is a reproducible example.

    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:

    TestGou-eps-converted-to.pdf

    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:

    TestFlat-eps-converted-to.pdf

    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.
    I would like to know where I'm doing something wrong. Thank you in advance for your help.

  6. anntzer commented on Jan 14, 2020

    Contributor

    Yes, I can confirm the difference now.

  7. QuLogic commented on Apr 21, 2023

    Member

    I'm not sure of the exact portion of the change that did it, but this was fixed by #23294.

  8. added this to the v3.6.0 milestone on Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL