Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New cycler does not work with bar plots #5854

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

Closed
bilderbuchi opened this issue Jan 14, 2016 · 6 comments
Closed

New cycler does not work with bar plots #5854

bilderbuchi opened this issue Jan 14, 2016 · 6 comments
Assignees
Milestone

Comments

@bilderbuchi
Copy link

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.

@WeatherGod
Copy link
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 <
[email protected]> 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.

@mdboom
Copy link
Member

mdboom commented Jan 14, 2016

#5674 addresses this issue (and others).

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

@WeatherGod
Copy link
Member

Right, I was talking about whatever has been released.

On Thu, Jan 14, 2016 at 12:28 PM, Michael Droettboom <
[email protected]> 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)
.

@bilderbuchi
Copy link
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?

@bilderbuchi
Copy link
Author

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

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Feb 15, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 4, 2016
repeated calls to `ax.bar` will advance the patch color cycle.

closes matplotlib#5854
@tacaswell tacaswell self-assigned this May 4, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 15, 2016
repeated calls to `ax.bar` will advance the patch color cycle.

closes matplotlib#5854
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 16, 2016
repeated calls to `ax.bar` will advance the patch color cycle.

closes matplotlib#5854
@bilderbuchi
Copy link
Author

awesome, thanks!

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

5 participants