Skip to content

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

Closed

Description

@RafiKueng

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

Activity

  1. RafiKueng commented on Jul 5, 2016

    @RafiKueng
    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...

  2. tacaswell commented on Jul 5, 2016

    @tacaswell
    Member

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

  3. afvincent commented on Jul 5, 2016

    @afvincent
    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

  4. tacaswell commented on Jul 5, 2016

    @tacaswell
    Member

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

  5. afvincent commented on Jul 5, 2016

    @afvincent
    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…

  6. afvincent commented on Jul 5, 2016

    @afvincent
    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

  7. added this to the milestone on Jul 11, 2016
  8. added 2 commits that reference this issue on Jul 12, 2016
    f67150a
    3ef3f5b
  9. asker4ik commented on Dec 30, 2019

    @asker4ik

    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

  10. bilderbuchi commented on Feb 12, 2020

    @bilderbuchi

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions