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

Matplotlib does not display hatching when rendering to pdf · Issue #29 · matplotlib/matplotlib · GitHub

Repository navigation

Matplotlib does not display hatching when rendering to pdf #29

Closed

Description

I am attempting to use the hatching feature in matplotlib, which works fine when displaying to screen. However when I save the figure to pdf format, the hatch marks are not rendered:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,100)

plt.figure()
plt.fill(x,np.sin(x),color='blue',alpha=0.5,hatch='/')
plt.show()
plt.savefig('./test.pdf',format='pdf')

I am using matplotlib 1.0.1 on OS X 10.6.6 (Specifically the Enthought Python Distribution v7).

Upon posting the issue initially to Stackoverflow, I received a workaround for the issue by using:

plt.fill(x,np.sin(x),color='blue',alpha=0.5)
plt.fill(x,np.sin(x),color='None',alpha=0.5,edgecolor='blue',hatch='/')

Not sure why this works, but it saves the pdf correctly when using the two commands in combination.

Activity

  1. jkseppan commented on Mar 4, 2011

    Member

    Among the arguments accepted by the fill function are color, edgecolor, facecolor, hatch, and alpha, and it's not obvious to me what the semantics should be, although it is clearly a bug that the agg and pdf backends create different output.

    My guess is that the agg backend fills the area with "color", then draws hatches with "color", and applies alpha compositing to the two operations separately so that the hatches show up as a darker shade of blue. The pdf backend creates a tiling pattern that includes both the hatch lines and the fill color and paints the area with that pattern, with alpha set to 0.5. The effect is a uniform blue color, since the pattern is just full of blue, and compositing it on the canvas just makes it lighter. The workaround works because there are two separate objects being drawn, so they are composited on top of each other.

    Should the pdf backend emulate the agg backend by drawing the hatch lines separately? Any other ideas?

    Relatedly, is the same "alpha" supposed to apply to both facecolor and edgecolor? What should happen if one of these is an RGBA tuple?

  2. ghost assigned on Jun 15, 2011
  3. skovhus commented on May 20, 2012

    What is the status of this issue?

  4. mdboom commented on May 23, 2012

    Member

    Perhaps related, the contourf_hatching.py demo throws an exception when saving to PDF.

  5. pelson commented on Jun 9, 2012

    Member

    Perhaps related, the contourf_hatching.py demo throws an exception when saving to PDF.

    I think that was a redherring which we managed to solve in #891.

    None the less, the example given in this issue now produces a pdf on master which, when viewed in evince, has the desired hatch pattern.

    @skovhus: Did you come across this issue because you are seeing the same problem?

  6. pelson commented on Jun 10, 2012

    Member

    I have just checked, and this is definitely fixed in v1.1.x branch (and hence 1.1.1rc2), although the hatching is made a little uglier by not having the hatch gap fix from #853 backported.

  7. mdboom commented on Jun 11, 2012

    Member

    Yeah -- unfortunately #853 also required changing the hatch spacing, so it's a fairly visible change and in my mind went beyond a bug fix -- but it's certainly in a grey area in that regard.

  8. added a commit that references this issue on Sep 22, 2016
  9. dirteat commented on Jan 27, 2021

    This is a "feature" of MAC OSX which is called "anti-aliasing".
    I've encountered the same problem recently (with recent version of mpl), the hatches are actually quite thin, and the MAC OSX PDF anti-aliasing filters just smooth them to vanish.

    Opening the same figure with Xpdf just works fine ;)

    It would be helpful to have some control on hatches thickness (mpl.rcParams[] seems to be ignored for hatches within a contourplot).

  10. WeatherGod commented on Jan 27, 2021

    Member

    @dirteat, could you open a new issue describing this problem in more detail? The original bug here is different, and we don't want to confuse the two (similar) problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL