Skip to content

New cycler does not work with bar plots #5854

Closed

Description

@bilderbuchi

I cannot get the new prop cycler to work with bar plots, it does not pick up the cycler properties at all.

I have minimally adapted the cycler demo to show this - see the ax1.bar calls. Running this gives two blue and one red bar plot, when it should give (in my expectation) one cyan, one magenta (from the cycle) and one red (manually set). The top axis' plot gets cycled correctly.

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

x = np.linspace(0, 2 * np.pi)
offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)
# Create array with shifted-sine curve along each column
yy = np.transpose([np.sin(x + phi) for phi in offsets])

plt.rc('lines', linewidth=4)
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
                           cycler('linestyle', ['-', '--', ':', '-.'])))
fig, (ax0, ax1) = plt.subplots(nrows=2)
ax0.plot(yy)
ax0.set_title('Set default color cycle to rgby')

ax1.set_prop_cycle(cycler('color', ['c', 'm', 'y', 'k']) +
                   cycler('lw', [1, 2, 3, 4]))
# ax1.plot(yy) # original
ax1.bar(x, yy[:,1])  # a simple bar plot from the available data
ax1.bar(x, yy[:,2])  # both these come out as blue
ax1.bar(x, yy[:,3], color='r')  # this works, gives red bars, so "color" is recognized!
ax1.set_title('Set axes color cycle to cmyk')

# Tweak spacing between subplots to prevent labels from overlapping
plt.subplots_adjust(hspace=0.3)
plt.show()

This is on mpl 1.5.1. Is this pebkac, or does the cycler only work for some plots (if so, which ones)?

Also, are hatches supported by this, too (I mean, as soon as it works)? That's what I ultimately want to do.

Activity

  1. WeatherGod commented on Jan 14, 2016

    @WeatherGod
    Member

    For the most part, in v1.5.x, the cycler will only work where-ever color
    cycling worked before. For the 2.0 release and beyond, we are working on
    getting more plots to support using the cycler features. Now, if you find a
    situation where color cycling works but other properties won't cycle, then
    that is most likely a real bug (except for pie()...).

    On Thu, Jan 14, 2016 at 11:10 AM, Christoph Buchner <
    notifications@github.com> wrote:

    I cannot get the new prop cycler to work with bar plots, it does not pick
    up the cycler properties at all.

    I have minimally adapted the cycler demo
    https://github.com/matplotlib/matplotlib/blob/0037595096e3be3ec863f3e3008e73c469e2f2b8/examples/color/color_cycle_demo.py
    to show this. Running this gives two blue and one red bar plot, when it
    should give (in my expectation) one cyan, one magenta (from the cycle) and
    one red (manually set).

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

    x = np.linspace(0, 2 * np.pi)
    offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)

    Create array with shifted-sine curve along each column

    yy = np.transpose([np.sin(x + phi) for phi in offsets])

    plt.rc('lines', linewidth=4)
    plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
    cycler('linestyle', ['-', '--', ':', '-.'])))
    fig, (ax0, ax1) = plt.subplots(nrows=2)
    ax0.plot(yy)
    ax0.set_title('Set default color cycle to rgby')

    ax1.set_prop_cycle(cycler('color', ['c', 'm', 'y', 'k']) +
    cycler('lw', [1, 2, 3, 4]))

    ax1.plot(yy) # original

    ax1.bar(x, yy[:,1]) # a simple bar plot from the available data
    ax1.bar(x, yy[:,2]) # both these come out as blue
    ax1.bar(x, yy[:,3], color='r') # this works, gives red bars, so "color" is recognized!
    ax1.set_title('Set axes color cycle to cmyk')

    Tweak spacing between subplots to prevent labels from overlapping

    plt.subplots_adjust(hspace=0.3)
    plt.show()

    This is on mpl 1.5.1. Is this pebkac, or does the cycler only work for
    some plots (if so, which ones)?

    —
    Reply to this email directly or view it on GitHub
    #5854.

  2. mdboom commented on Jan 14, 2016

    @mdboom
    Member

    #5674 addresses this issue (and others).

    @WeatherGod: Why do you call out pie. #5674 fixes pie as well?

  3. WeatherGod commented on Jan 14, 2016

    @WeatherGod
    Member

    Right, I was talking about whatever has been released.

    On Thu, Jan 14, 2016 at 12:28 PM, Michael Droettboom <
    notifications@github.com> wrote:

    #5674 #5674 addresses this
    issue (and others).

    @WeatherGod https://github.com/WeatherGod: Why do you call out pie.
    #5674 #5674 fixes pie as
    well?

    —
    Reply to this email directly or view it on GitHub
    #5854 (comment)
    .

  4. bilderbuchi commented on Jan 15, 2016

    @bilderbuchi
    Author

    For the most part, in v1.5.x, the cycler will only work where-ever color cycling worked before.

    OK, so bar plots basically can't digest cycles if I understand correctly. Thanks, I missed that.

    #5674 addresses this issue.

    really, how? It only talks about colors afaict, but not about property cycles (which can have properties other than color, e.g. hatch) for bar plots, if I haven't missed something?

  5. bilderbuchi commented on Jan 15, 2016

    @bilderbuchi
    Author

    @WeatherGod should I close this, then, or leave it open until next-major-release?

  6. added this to the milestone on Feb 15, 2016
  7. added a commit that references this issue on May 4, 2016
    773ca61
  8. self-assigned this
    on May 4, 2016
  9. added 3 commits that reference this issue on May 15, 2016
    5fb3a58
    572e0da
    5a7dab7
  10. bilderbuchi commented on May 24, 2016

    @bilderbuchi
    Author

    awesome, thanks!

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