You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes plots (especially histograms with narrow bins) have small features that are obscured or missed by ordinary dashed line plots.
Proposed Solution
Add the ability to specify an offcolor=(0.0, 0.0, 0.0, 0.0) kwarg that fills in the blanks when a dashed line style, or dash pattern, is used. In principle, even more colors could be specified, but a simple on-color/off-color would be sufficient and require the fewest changes to the API.
This can already be done by plotting multiple lines that have carefully matching dash patterns, but the issue is that the stripes aren't represented in plot legends.
Additional context and prior art
Right now I do this with this function (where the off-color is set to half the opacity of the oncolor):
def plotstripedline(ax, xvals, yvals, oncolor, dashpattern, lname):
if len(oncolor) != 4:
raise ValueError(
"oncolor must have four floating point elements 0 to 1, rgba.")
linestyle = (0, dashpattern)
ax.plot(xvals, yvals, ls=linestyle, color=oncolor,
label=lname)
gapdp = list(dashpattern[1:])
gapdp.append(dashpattern[0])
gapstyle = (-dashpattern[0], gapdp)
gapcol = [ x for x in oncolor ]
gapcol[-1] *= 0.5
ax.plot(xvals, yvals, ls=gapstyle, color=gapcol)
return None
While this implementation is discussed, I believe you can make do with the following code:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 2*np.pi, 0.2)
y = np.cos(x)
blue_line, = plt.plot(x, y, linestyle='-', lw=3)
dashed_line, = plt.plot(x, y, linestyle=(2, (2, 2)), lw=3)
plt.legend([(blue_line, dashed_line)], ['data'])
I looked briefly at the tutorials and it seems the legends in matplotlib are very powerful! If you wish, you can check more interesting examples about legends here.
Someone would have to dig into linestyles to do this, and figure out a reasonable API for specifying the style. Other stroke styles have been discussed in the past, so there may be a desire to make a "LineStyle" container class for specifying. I'd say this is rather involved, but not an unreasonable request.
On Wed, Aug 26, 2020 at 10:05 AM Jody Klymak ***@***.***> wrote:
Someone would have to dig into linestyles to do this, and figure out a
reasonable API for specifying the style. Other stroke styles have been
discussed in the past, so there may be a desire to make a "LineStyle"
container class for specifying. I'd say this is rather involved, but not an
unreasonable request.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#18351 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6EHOQ7N2XRYDPQ566LSCUJDVANCNFSM4QKIILZA>
.
This sort of is similar to #12980, in particular #12980 (comment) which talks about pen and stroke styles. I think it'd be a lot of work to do this, however.
I guess alt_color is a possibility. It would be less flexible, but certainly a more tractable problem.
This sort of is similar to #12980, in particular #12980 (comment) which talks about pen and stroke styles. I think it'd be a lot of work to do this, however.
AFAICS #12980 is quite different. It has a single shaped pen, whereas here, you change between two differently colored "simple" pens. I don't think one of the problems can be expressed as the other.
But I agree that #12980 would be a lot of work, and alt_color is significantly simpler.
On Wed, Aug 26, 2020 at 5:05 PM Tim Hoffmann ***@***.***> wrote:
This sort of is similar to #12980
<#12980>, in particular
#12980 <#12980> (comment)
which talks about pen and stroke styles. I think it'd be a lot of work to
do this, however.
AFAICS #12980 <#12980> is
quite different. It has a single shaped pen, whereas here, you change
between two differently colored "simple" pens. I don't think one of the
problems can be expressed as the other.
But I agree that #12980
<#12980> would be a lot of
work, and alt_color is significantly simpler.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18351 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6GVIHT7TOEX5CSIXMLSCV2I3ANCNFSM4QKIILZA>
.
Hello,
I am a student in software engineering and I work with a fellow student on a project. We would like to contribute on the implementation of this functionality
I think the new-artist-proposal is not feasible. This would get us in all sorts of synchronization trouble:
What if the user changes data -> would have to be synchronously propagated to both child artists.
What should we do if the user changes linestyle from/to solid?
The correct solution is to dig into the low-level drawing and draw the spaces there as well.
We will need a discussion at some point on proper naming of the parameter (gapcolor / coloralt / alt_color), but that should not stop you to start writing that functionality. - Renaming is easy.
Organizational remarks
tl;dr: Please reflect if you've feel largely capable of the task. No offence meant. I'll assume you do, but want to make sure that we don't get into troubles down the road.
We've had mixed experiences with student projects. Some resulted in valuable contributions, some ended up abandoned after a lot of back and forth. To prevent troubles down the road, I'd like to set expectations:
We welcome contributions from people with all experience levels. However, the difficulty of the task should match the experience. We'll happily give advice on specific aspects, but we're no teaching site (We don't have the capacity for requests "I'd like to work on this issue. Please walk me through step-by-step what I should do).
This issue is marked as medium-difficult. You should be able to find the relevant code locations and propose reasonable changes yourself. If you need help with some details, don't hesitate do ask.
CC @story645 as our community lead: Please check if wording and content matches our policy.
Give or take - our code base is dense enough that I think it's okay to ask/confirm about relative code locations, but a lot of that thrashing will happen on the PR. @lucielavigne please don't take @timhoffm's response as dissuading you from contributing; if you're unsure about how much guidance you'll need, open a draft and we can take it from there. If you end up needing more help than we have the bandwidth for, we'll be at the PyData global sprints (which should be open to the public) https://global.pydata.org/talks/matplotlib
Hi,
We are three students working on it, we have 6 weeks to work on it. We are willing to solve the issue.
However the link you gave me is not working.
We looked at the previous comments and the code, maybe you could give us some pointers to narrow our searchs.
Thank you
Activity
diegopetrola commentedon Aug 26, 2020
While this implementation is discussed, I believe you can make do with the following code:
I looked briefly at the tutorials and it seems the legends in
matplotlibare very powerful! If you wish, you can check more interesting examples about legends here.jklymak commentedon Aug 26, 2020
Someone would have to dig into linestyles to do this, and figure out a reasonable API for specifying the style. Other stroke styles have been discussed in the past, so there may be a desire to make a "LineStyle" container class for specifying. I'd say this is rather involved, but not an unreasonable request.
WeatherGod commentedon Aug 26, 2020
tacaswell commentedon Aug 26, 2020
I agree with @jklymak 's assessment and @WeatherGod
An immediate path would be to make a new artist that has as children the 2 lines in @diegopetrola 's comment.
timhoffm commentedon Aug 26, 2020
API-wise an
alt_colordefaulting to transparent is enough.jklymak commentedon Aug 26, 2020
This sort of is similar to #12980, in particular #12980 (comment) which talks about pen and stroke styles. I think it'd be a lot of work to do this, however.
I guess
alt_coloris a possibility. It would be less flexible, but certainly a more tractable problem.timhoffm commentedon Aug 26, 2020
AFAICS #12980 is quite different. It has a single shaped pen, whereas here, you change between two differently colored "simple" pens. I don't think one of the problems can be expressed as the other.
But I agree that #12980 would be a lot of work, and
alt_coloris significantly simpler.WeatherGod commentedon Aug 26, 2020
timhoffm commentedon Aug 26, 2020
Maybe. Even though I find that quite unreadable. Alternatively, we could find something new like
gapcolor.lucielavigne commentedon Oct 21, 2020
Hello,
I am a student in software engineering and I work with a fellow student on a project. We would like to contribute on the implementation of this functionality
timhoffm commentedon Oct 21, 2020
@lucielavigne You are welcome to!
Technical remarks
I think the new-artist-proposal is not feasible. This would get us in all sorts of synchronization trouble:
The correct solution is to dig into the low-level drawing and draw the spaces there as well.
We will need a discussion at some point on proper naming of the parameter (
gapcolor/coloralt/alt_color), but that should not stop you to start writing that functionality. - Renaming is easy.Organizational remarks
tl;dr: Please reflect if you've feel largely capable of the task. No offence meant. I'll assume you do, but want to make sure that we don't get into troubles down the road.
We've had mixed experiences with student projects. Some resulted in valuable contributions, some ended up abandoned after a lot of back and forth. To prevent troubles down the road, I'd like to set expectations:
We welcome contributions from people with all experience levels. However, the difficulty of the task should match the experience. We'll happily give advice on specific aspects, but we're no teaching site (We don't have the capacity for requests "I'd like to work on this issue. Please walk me through step-by-step what I should do).
This issue is marked as medium-difficult. You should be able to find the relevant code locations and propose reasonable changes yourself. If you need help with some details, don't hesitate do ask.
CC @story645 as our community lead: Please check if wording and content matches our policy.
story645 commentedon Oct 22, 2020
Give or take - our code base is dense enough that I think it's okay to ask/confirm about relative code locations, but a lot of that thrashing will happen on the PR. @lucielavigne please don't take @timhoffm's response as dissuading you from contributing; if you're unsure about how much guidance you'll need, open a draft and we can take it from there. If you end up needing more help than we have the bandwidth for, we'll be at the PyData global sprints (which should be open to the public) https://global.pydata.org/talks/matplotlib
lucielavigne commentedon Nov 4, 2020
Hi,
We are three students working on it, we have 6 weeks to work on it. We are willing to solve the issue.
However the link you gave me is not working.
We looked at the previous comments and the code, maybe you could give us some pointers to narrow our searchs.
Thank you
timhoffm commentedon Nov 4, 2020
I did not look closely at this, but I suppose you need to draw a second path with the inverted pattern at
matplotlib/lib/matplotlib/lines.py
Line 787 in 6928693
story645 commentedon Nov 4, 2020
Sorry, the new link is https://global.pydata.org/talks/99, but there aren't details posted yet so check back at https://gitter.im/matplotlib/matplotlib
lucielavigne commentedon Dec 1, 2020
Hello,
I submitted a pull request under add the ability to plot stripped lines.