Skip to content

Using a linestyle cycler with plt.errorbar results in strange plots #7074

Closed

Description

@Chroxvi

If the linestyles used in a plt.errorbar plot are adjusted manually, results are as expected. However, when using a linestyle cycler, the linestyles are simply ignored whereas using a ls cycler results in errorbar end points being connected by lines.

Consider the following minimal example

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from cycler import cycler

x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)
offsets = [0, 1]


linestyles = ['-', '--']

plt.figure()
for offset, linestyle in zip(offsets, linestyles):
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, ls=linestyle, color='b')
plt.title('manual plots')
plt.savefig('manual_plots.png')


linestyle_cycle = cycler('linestyle', linestyles)
mpl.rcParams['axes.prop_cycle'] = linestyle_cycle

plt.figure()
for offset in offsets:
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, color='b')
plt.title('Linestyle cycler plots')
plt.savefig('linestyle_cycler_plots.png')


ls_cycle = cycler('ls', linestyles)
mpl.rcParams['axes.prop_cycle'] = ls_cycle

plt.figure()
for offset in offsets:
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, color='b')
plt.title('ls cycler plots')
plt.savefig('ls_cycler_plots.png')

which produces the following set of figures

manual_plots
linestyle_cycler_plots
ls_cycler_plots

I ran the above example using Anaconda 4.1.1 with Python 3.5.2 and Matplotlib 1.5.1 on Linux.

Activity

  1. WeatherGod commented on Sep 9, 2016

    @WeatherGod
    Member

    I believe this was fixed in subsequent versions of matplotlib v1.5.x
    branch. Note that we are right now trying to get Continuum to push out a
    v1.5.3 package through conda which was tagged last night. For some reason,
    conda never picked up v1.5.2 (but I don't remember if that release
    contained the needed fixes for this).

    On Fri, Sep 9, 2016 at 9:44 AM, Christian Schou Oxvig <
    notifications@github.com> wrote:

    If the linestyles used in a plt.errorbar plot are adjusted manually,
    results are as expected. However, when using a linestyle cycler, the
    linestyles are simply ignored whereas using a ls cycler results in
    errorbar end points being connected by lines.

    Consider the following minimal example

    import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltfrom cycler import cycler

    x = np.arange(0.1, 4, 0.5)
    y = np.exp(-x)
    offsets = [0, 1]

    linestyles = ['-', '--']

    plt.figure()for offset, linestyle in zip(offsets, linestyles):
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, ls=linestyle, color='b')
    plt.title('manual plots')
    plt.savefig('manual_plots.png')

    linestyle_cycle = cycler('linestyle', linestyles)
    mpl.rcParams['axes.prop_cycle'] = linestyle_cycle

    plt.figure()for offset in offsets:
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, color='b')
    plt.title('Linestyle cycler plots')
    plt.savefig('linestyle_cycler_plots.png')

    ls_cycle = cycler('ls', linestyles)
    mpl.rcParams['axes.prop_cycle'] = ls_cycle

    plt.figure()for offset in offsets:
    plt.errorbar(x, y + offset, xerr=0.1, yerr=0.3, color='b')
    plt.title('ls cycler plots')
    plt.savefig('ls_cycler_plots.png')

    which produces the following set of figures

    [image: manual_plots]
    https://cloud.githubusercontent.com/assets/5367057/18388683/e20efd1a-76a2-11e6-8c96-364205a656b0.png
    [image: linestyle_cycler_plots]
    https://cloud.githubusercontent.com/assets/5367057/18388687/e670a52a-76a2-11e6-8f56-9c01664443c0.png
    [image: ls_cycler_plots]
    https://cloud.githubusercontent.com/assets/5367057/18388690/e93dad52-76a2-11e6-8883-d2a526cab9d1.png

    I ran the above example using Anaconda 4.1.1 with Python 3.5.2 and
    Matplotlib 1.5.1 on Linux.

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly, view it on GitHub
    #7074, or mute the thread
    https://github.com/notifications/unsubscribe-auth/AARy-DK1HCMZfVEuprOvPmGBVmNspEIoks5qoWLagaJpZM4J5EJI
    .

  2. QuLogic commented on Sep 9, 2016

    @QuLogic
    Member

    The same set of figures is produced with 1.5.3. On the v2.x branch, both linestyle and ls cyclers produce the same results, though I'm not sure they're the expected results.
    manual_plots
    linestyle_cycler_plots
    ls_cycler_plots

  3. WeatherGod commented on Sep 9, 2016

    @WeatherGod
    Member

    Hmm, I wonder if the plot() calls inside of errorbar() might be mishandling
    some things...

    The ls cycler image using 1.5.1 shows that the ls cycler is being used for
    the plot()'s of the errorbar markers. This is obviously incorrect, and is
    somehow fixed in v2.x. The next problem is how to get the main plot() call
    to utilize the cycler if no linestyle is specified. I wonder if errorbar()
    is passing in its own linestyle?

    On Fri, Sep 9, 2016 at 4:19 PM, Elliott Sales de Andrade <
    notifications@github.com> wrote:

    The same set of figures is produced with 1.5.3. On the v2.x branch, both
    linestyle and ls cyclers produce the same results, though I'm not sure
    they're the expected results.
    [image: manual_plots]
    https://cloud.githubusercontent.com/assets/302469/18401561/10fc9078-76a9-11e6-9350-6fa1580bc40e.png
    [image: linestyle_cycler_plots]
    https://cloud.githubusercontent.com/assets/302469/18401567/13dd758c-76a9-11e6-9ded-a545a061ab35.png
    [image: ls_cycler_plots]
    https://cloud.githubusercontent.com/assets/302469/18401570/15f9a9ee-76a9-11e6-8949-6cf84ff0bf92.png

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #7074 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AARy-CIvPX7wb8Q8jBh_tzbRm-RWTUIBks5qob9KgaJpZM4J5EJI
    .

  4. tacaswell commented on Sep 11, 2016

    @tacaswell
    Member

    The guts of errorbar were almost completely re-written in #5593

  5. added this to the milestone on Mar 14, 2017
  6. modified the milestones: , on May 3, 2017
  7. modified the milestones: , on Oct 9, 2017
  8. self-assigned this
    on Jul 14, 2020
  9. added 4 commits that reference this issue on Jul 15, 2020
    11e2f92
    d810348
    1c59fb0
    77ff26a
  10. added 3 commits that reference this issue on Aug 19, 2020
    1db6936
    f488a22
    149e7fb
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