-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow multiple hatch colors in same figure #7901
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
To make matters worse, it looks to me that the hatch color is hardcoded in the backend in such a way that it's not possible to have more than one hatch color. Therefore I don't know how to produce a figure like this with mpl2: |
#7059 is roughly related |
I've also encountered the same problem. It seems that PR #7415 broke what I believe should be a supported functionality, i.e. using hatching with different colors within one figure. I want to add further support for the Zaharid's suggestion of adding a kw argument for addressing this issue. Otherwise I think it might even be preferable to revert the PR. There is a slight gain of convenience from being able to set a global default hatching color, but a net loss in functionality. (Plotting with hatch color != edgecolor could also be achieved before by plotting the artist twice once with hatching and once without.) |
That #7415 fixed #7166 which was hatches not showing up in the legend so it can not be reverted. The fix for 2.0.1 could be:
This will give the behavior of:
I want to hold off adding the |
I fully endorse this request to have an interface to the hatch's color, linestyle, linewidth, alpha etc. The feature to control those parameters has been present in previous versions (at least color and linewidth) and it was a big mistake to change this. Let me elaborate a bit on the necessity of controling the hatch. Another point is of course that different styled hatching allows to add a new dimension to a figure. What is linecolor, linestyle and linewidth in 1D is patchcolor and hatch in 2D. Controlling the hatch is therefore utterly important. |
@ImportanceOfBeingErnest Can you open a new issue with that? That sort of effect maybe beyond the scope of what the hatching can currently do (or maybe we only need linewidth?). I think a MEP (https://github.com/matplotlib/matplotlib/tree/master/doc/devel/MEP) proposing an API for what this would look like and how to implement it across all of the backends would be well received. Given that you have clearly thought about this, can you take a crack at that? |
I don't think we need a new issue here, it is exactly what @Zaharid is asking for: The plot from above can actually be reproduced in matplotlib 2.0 in a very hacky way. The only thing really missing here is the ability to change hatchcolor, hatchlinewidth and density via the api.
|
Fair, I had not grasped how useful the However, your comment about how hatch selection works is not quite correct, see https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/hatch.py#L194 . It creates hatch objects for all of the hatch types it know about and merges them. It happens that I would like to significantly narrow the scope of this issue to be fixing the no-multi-color-hatch regression in 2.0 and am asking for a new issue to work through all of the hatch-related knobs that will need to be added and which bits of configuration that are currently hard-coded or global parameters need to be pulled up to artist-level configuration. |
Just to chime in, there is a nice example of setting per-patch hatching color here under the 'Colors' section, which worked in 1.5 but doesn't in 2.0 . As others have pointed out, if you want a plot that works both in color and in black and white it's critical to be able to adjust the hatch color for each patch (and eventually all sorts of other things too like width and spacing etc) |
@mangecoeur This should work again in 2.0.1 (fixed by #7976) |
(that is when we release 2.0.1) |
Hi. What is preferred way to achieve colored hatch currently? Currently my graph looks like: From reading above, it looks like:
Should I better:
|
@hughperkins Your understanding is correct and those are the two options. 2.0.1 should be very soon. |
Hi, The problem with this is that the legends become useless. Is there something we can use instead to mimic this behaviour without using
|
Use |
Ugh.... Thanks. I had futilely tried |
@kamraaan1997 Please open a new issue with a minimal example that shows a bug or if you are looking for support on how to use Matplotlib please post your question to https://discourse.matplotlib.org . Thank you! |
In version 2.0 the hatching defaults have changed. In particular, the color is always black by default and it is now inconvenient to restore the old way in which the colors are set (based on the artist line color at least for
fill_between
).I'd like to request a
hatchcolor
parameter for the functions that accept hatches.The text was updated successfully, but these errors were encountered: