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

Bug in pyplot.plot() with zorder/solid_capstyle kwarg combinations #4262

Closed
megies opened this issue Mar 22, 2015 · 6 comments
Closed

Bug in pyplot.plot() with zorder/solid_capstyle kwarg combinations #4262

megies opened this issue Mar 22, 2015 · 6 comments

Comments

@megies
Copy link
Contributor

megies commented Mar 22, 2015

There is a strange bug that changes the color used in the plot, happening to me for certain combinations of zorder and solid_capstyle kwargs. Happens to me on matplotlib 1.4.3 installed through anaconda/conda package (tried it with TKAGG and QT4AGG).

import matplotlib.pyplot as plt

plt.subplot(321)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20, zorder=None)
plt.title("zorder=None")
plt.subplot(322)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20, zorder=None, solid_capstyle="round")
plt.title('zorder=None, solid_capstyle="round"')
plt.subplot(323)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20, zorder=10)
plt.title('zorder=10')
plt.subplot(324)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20, zorder=10, solid_capstyle="round")
plt.title('zorder=10, solid_capstyle="round"')
plt.subplot(325)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20)
plt.title('')
plt.subplot(326)
plt.plot([0, 1], [0, 1], c="black", ls="-", lw=20, solid_capstyle="round")
plt.title('solid_capstyle="round"')

plt.tight_layout()
plt.show()

figure_1

@tacaswell
Copy link
Member

well, that is a fun bug....

I can't reproduce this on master and the zorder=None examples raise an exception that None is not orderable (on py3k).

With 1.4.3 + py3k I still get exceptions for zorder=None, and get different results (all blue, and sometimes the middle right one is black.

I also simplified the code a bit:

import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 2)

dicts = [[dict(c="black", ls="-", lw=20),
          dict(c="black", ls="-", lw=20, solid_capstyle="round")],
          [dict(c="black", ls="-", lw=20, zorder=10),
           dict(c="black", ls="-", lw=20, zorder=10, solid_capstyle="round")],
          [dict(c="black", ls="-", lw=20),
           dict(c="black", ls="-", lw=20, solid_capstyle="round")]
          ]

for row, kwargs in zip(axs, dicts):
    for ax, style in zip(row, kwargs):
        ax.plot([0, 1], [0, 1], **style)
        ax.set_title('{!r}'.format(style))

plt.tight_layout()
plt.show()

Just to be sure there was no funny state-machine related shenanigans going on.

@tacaswell
Copy link
Member

And on 2.7 I get almost the same result as @megies.

This is probably related to the use of self.update(**kwargs) is the __init__ of Line2D which ends up being dependent on the order of iterations through the dictionary.

@tacaswell
Copy link
Member

Changing c -> color works in all cases on 2.7 and 3.4.

@tacaswell tacaswell added this to the next point release milestone Mar 22, 2015
@efiring
Copy link
Member

efiring commented Mar 22, 2015

This was fixed in master with #4198.

@megies
Copy link
Contributor Author

megies commented Mar 25, 2015

This was fixed in master with #4198.

Sorry for not checking against master before reporting. I was on the road and in a bit of a hurry. Thanks for clarifying.

@tacaswell
Copy link
Member

It reminded us that this should be back ported so not a waste.

megies referenced this issue in obspy/obspy Oct 28, 2015
The c argument is sometimes overridden depending on dictionary iteration
order; color can be used without issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants