-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix axes.set_prop_cycle to handle any generic iterable sequence. #5452
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Closes issue #5368.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from matplotlib.testing.decorators import image_comparison | ||
from matplotlib.testing.decorators import image_comparison, cleanup | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from nose.tools import assert_raises | ||
|
||
from cycler import cycler | ||
|
||
|
@@ -42,6 +43,27 @@ def test_marker_cycle(): | |
ax.legend(loc='upper left') | ||
|
||
|
||
# Reuse the image from test_marker_cycle() | ||
@image_comparison(baseline_images=['marker_cycle'], remove_text=True, | ||
extensions=['png']) | ||
def test_marker_cycle_keywords(): | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111) | ||
# Test keyword arguments, numpy arrays, and generic iterators | ||
ax.set_prop_cycle(color=np.array(['r', 'g', 'y']), | ||
marker=iter(['.', '*', 'x'])) | ||
xs = np.arange(10) | ||
ys = 0.25 * xs + 2 | ||
ax.plot(xs, ys, label='red dot', lw=4, ms=16) | ||
ys = 0.45 * xs + 3 | ||
ax.plot(xs, ys, label='green star', lw=4, ms=16) | ||
ys = 0.65 * xs + 4 | ||
ax.plot(xs, ys, label='yellow x', lw=4, ms=16) | ||
ys = 0.85 * xs + 5 | ||
ax.plot(xs, ys, label='red2 dot', lw=4, ms=16) | ||
ax.legend(loc='upper left') | ||
|
||
|
||
@image_comparison(baseline_images=['lineprop_cycle_basic'], remove_text=True, | ||
extensions=['png']) | ||
def test_linestylecycle_basic(): | ||
|
@@ -104,6 +126,45 @@ def test_fillcycle_ignore(): | |
ax.legend(loc='upper left') | ||
|
||
|
||
@cleanup | ||
def test_valid_input_forms(): | ||
fig, ax = plt.subplots() | ||
# These should not raise an error. | ||
ax.set_prop_cycle(None) | ||
ax.set_prop_cycle(cycler('linewidth', [1, 2])) | ||
ax.set_prop_cycle('color', 'rgywkbcm') | ||
ax.set_prop_cycle('linewidth', (1, 2)) | ||
ax.set_prop_cycle('linewidth', [1, 2]) | ||
ax.set_prop_cycle('linewidth', iter([1, 2])) | ||
ax.set_prop_cycle('linewidth', np.array([1, 2])) | ||
ax.set_prop_cycle('color', np.array([[1, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 1]])) | ||
ax.set_prop_cycle(lw=[1, 2], color=['k', 'w'], ls=['-', '--']) | ||
ax.set_prop_cycle(lw=np.array([1, 2]), | ||
color=np.array(['k', 'w']), | ||
ls=np.array(['-', '--'])) | ||
assert True | ||
|
||
|
||
@cleanup | ||
def test_invalid_input_forms(): | ||
fig, ax = plt.subplots() | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle(1) | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle([1, 2]) | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle('color', 'fish') | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle('linewidth', 1) | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle('linewidth', {'1':1, '2':2}) | ||
with assert_raises((TypeError, ValueError)): | ||
ax.set_prop_cycle(linewidth=1, color='r') | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one too many blank lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I see that from the pep8 failure on Travis. It also complained about not having a space after the colon in the dictionary |
||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't use assert_raises as a context manager if you want this to go into the 1.5.x branch. Nose doesn't provide that context manager for python 2.6 for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note, since this PR is set up to merge into master, it is ok to keep it this way. Just that the person who backports this has to convert it to the non context manager form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the what's new page, matplotlib 1.5 dropped support for python 2.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, sorry. That was a last minute change that went into 1.5 prior to
release. Carry on.
On Mon, Nov 9, 2015 at 4:44 PM, u55 notifications@github.com wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew this was going to be confusing when we decided this awhile ago...
It is that official support for 2.6 ended for v1.5, but it seems that we still have Travis testing v1.5.x branch with python2.6. So, whoever backports this PR should be aware of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WeatherGod
I only see Travis running tests for versions: 2.7, 3.4, 3.5, and the nightly build 3.6.0a0. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/matplotlib/matplotlib/blob/v1.5.x/.travis.yml
That is the way it is configured on the 1.5.x branch. Your PR is against master, which is configured differently. But don't worry about it. I will take care of it when I backport this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I see. Thank you for the explanation.