Skip to content
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

linestyle="None" argument for fill_between() doesn't work #6693

Closed
RafiKueng opened this issue Jul 5, 2016 · 8 comments
Closed

linestyle="None" argument for fill_between() doesn't work #6693

RafiKueng opened this issue Jul 5, 2016 · 8 comments
Milestone

Comments

@RafiKueng
Copy link

fill_between() doesn't accept all possible linestyles (esp. empty ones..)

import matplotlib.pyplot as plt
plt.fill_between([1,2,3], [4,5,6], 5, linestyle="None")

ValueError: Do not know how to convert None to dashes

The same for "" and " "

[ mpl: 1.5.1; python 2.7.9; OpenSUSE; user install by pip (pip install --user matplotlib) ]

@RafiKueng
Copy link
Author

Unfortunately, I don't know the code at all, but I guess a fix would need to add here:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/cbook.py#L2022

_linestyles = [('-', 'solid'),
               ('--', 'dashed'),
               ('-.', 'dashdot'),
               (':', 'dotted'),
               ('', 'none'),
               (' ', 'none'),
               ('None', 'none')
]

and then to add the a return value (offset, dashes) for style 'none' here:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/lines.py#L37

Unfortunately, I don't know what are valid (offset, dashes) that lead to no line...

@tacaswell
Copy link
Member

Can you try with the 2.0.0b1 or 1.5.2 releases? I think we fixed this in another way.

@afvincent
Copy link
Contributor

@tacaswell Are you sure it has been fixed? Because with mpl '2.0.0b1.post1771+g5dfe000', plt.fill_between([1,2,3], [4,5,6], 5, linestyle=MyLS) with the tested “MyLS” being("None", " ", "") still raises ValueError: Do not know how to convert None to dashes

@tacaswell
Copy link
Member

Then no 😞 We fixed some other normalization of the dashes then.

@afvincent
Copy link
Contributor

It looks like @RafiKueng is right about the origin of the error: mlines.get_dash_pattern expects only an argument in {'solid', 'dashed', 'dotted', 'dashdot'}, but unfortunately, here this method is called by mcollections.Collection.set_linestyle which also accept arguments like "None" that are not transformed into any of those 4 names by cbook.ls_mapper.get before calling mlines.get_dash_pattern

@afvincent
Copy link
Contributor

I've been playing a bit with the linestyle options of fill_between and I've encountered several weird behaviors. Is the following script

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import NullLocator


def plot_test(ax, ls=None, lw=None):
    _plot_opts = dict(facecolor='LightGrey', edgecolor='Black')
    ax.set_title("ls:'{ls}' & lw: {lw}".format(ls=ls, lw=lw))
    ax.fill_between([1, 2, 3], [4, 5, 6], 5, linestyle=ls, lw=lw, **_plot_opts)
    ax.xaxis.set_major_locator(NullLocator())
    ax.yaxis.set_major_locator(NullLocator())
    return ax


if __name__ == "__main__":

    fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2,
                                                 num=mpl.__version__)

    ax0 = plot_test(ax0, ls='dashed', lw=2)
    ax1 = plot_test(ax1, ls='dashed', lw=10)
    ax2 = plot_test(ax2, ls='dashed', lw=None)
    ax3 = plot_test(ax3, ls='solid', lw=0)

    fig.savefig(fig.get_label() + '.png', dpi=100)

supposed to produce (with mpl 2.0.0b1.post1771+g5dfe000)
2 0 0b1 post1771 g5dfe000
? First, the dashes don't seem to scale accordingly to the linewidth. Second if lw is None (default) then even with a named linestyle, no edge line is visible.

It seems however to me that the result was OK with mpl 1.5.1 (anaconda2):
1 5 1

@jenshnielsen jenshnielsen added this to the 2.0 (style change major release) milestone Jul 11, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 12, 2016
When scaling the dash pattern by the linewidth do the scaling at artist
creation / value set time rather than at draw time.

closes matplotlib#6592
closes matplotlib#6588
closes matplotlib#6590
Closes matplotlib#6693
closes matplotlib#5430
@asker4ik
Copy link

fill_between() doesn't accept all possible linestyles (esp. empty ones..)

import matplotlib.pyplot as plt
plt.fill_between([1,2,3], [4,5,6], 5, linestyle="None")

ValueError: Do not know how to convert None to dashes

The same for "" and " "

[ mpl: 1.5.1; python 2.7.9; OpenSUSE; user install by pip (pip install --user matplotlib) ]

should be linestyle = 'none'. case sensitive

@bilderbuchi
Copy link

@asker4ik this works for you? When I do that, I still get ValueError: Do not know how to convert 'none' to dashes with mpl 3.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants