Step linestyle #1802

Merged
merged 7 commits into from Mar 23, 2013

Projects

None yet

5 participants

@tacaswell
Member

Looked at this because of http://stackoverflow.com/questions/15188005/linestyle-in-matplotlib-step-function/15191183#15191183

The step function is just a light wrapper of plot. Added a step to append the user specified linestyle onto the argument passed to plot instead of silently ignoring it.

Includes a unit test (there is currently no other test-coverage of step).

Based this against master because I am not sure if this is really a bug, or if I am changing an intentional interface.

@NelleV NelleV and 1 other commented on an outdated diff Mar 4, 2013
lib/matplotlib/tests/test_axes.py
@@ -1187,3 +1187,30 @@ def test_eb_line_zorder():
if __name__=='__main__':
@NelleV
NelleV Mar 4, 2013 Contributor

You need to remove this.

@tacaswell
tacaswell Mar 4, 2013 Member

Not sure what you mean here. My editor removes white space at the end of lines when it saves so this looks like an un-intentional pep8 fix to me.

@NelleV
NelleV Mar 4, 2013 Contributor

the code if __name__ == "__main__" is duplicated in this file. It should be at the bottom of the file only, and not in the middle of the module. As you added it again after your code, you need to remove line 1187 to line 1189.

@tacaswell
tacaswell Mar 4, 2013 Member

right, I was looking at the wrong bit of code.

@NelleV NelleV commented on an outdated diff Mar 4, 2013
lib/matplotlib/tests/test_axes.py
@@ -1187,3 +1187,30 @@ def test_eb_line_zorder():
if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
+
@NelleV
NelleV Mar 4, 2013 Contributor

There should be only 2 blank lines between the end of the previous function and the beginning of the next function (PEP8 compliance).

@NelleV NelleV commented on the diff Mar 4, 2013
lib/matplotlib/tests/test_axes.py
+ x = y = np.arange(10)
+
+ # First illustrate basic pyplot interface, using defaults where possible.
+ fig, ax_lst = plt.subplots(2, 2)
+ ax_lst = ax_lst.flatten()
+
+ ln_styles = ['-', '--', '-.', ':']
+
+ for ax, ls in zip(ax_lst, ln_styles):
+ ax.step(x, y, lw=5, linestyle=ls, where='pre')
+ ax.step(x, y + 1, lw=5, linestyle=ls, where='mid')
+ ax.step(x, y + 2, lw=5, linestyle=ls, where='post')
+ ax.set_xlim([-1, 5])
+ ax.set_ylim([-1, 7])
+
+
@NelleV
NelleV Mar 4, 2013 Contributor

There should be only two blank lines here.

@NelleV NelleV commented on an outdated diff Mar 4, 2013
lib/matplotlib/tests/test_axes.py
+ ax_lst = ax_lst.flatten()
+
+ ln_styles = ['-', '--', '-.', ':']
+
+ for ax, ls in zip(ax_lst, ln_styles):
+ ax.step(x, y, lw=5, linestyle=ls, where='pre')
+ ax.step(x, y + 1, lw=5, linestyle=ls, where='mid')
+ ax.step(x, y + 2, lw=5, linestyle=ls, where='post')
+ ax.set_xlim([-1, 5])
+ ax.set_ylim([-1, 7])
+
+
+
+if __name__=='__main__':
+ import nose
+ nose.runmodule(argv=['-s','--with-doctest'], exit=False)
@NelleV
NelleV Mar 4, 2013 Contributor

There should be a space after ,

@tacaswell
Member

Sorry about the style issues.

@tacaswell
Member

The 2.6 failure is related to pip and pyparsing

@mdboom
Member
mdboom commented Mar 5, 2013

The build error looks to just be a networking timeout. Typical for travis.

@NelleV NelleV and 1 other commented on an outdated diff Mar 15, 2013
lib/matplotlib/axes.py
@@ -4793,7 +4793,8 @@ def step(self, x, y, *args, **kwargs):
if where not in ('pre', 'post', 'mid'):
raise ValueError("'where' argument to step must be "
"'pre', 'post' or 'mid'")
- kwargs['linestyle'] = 'steps-' + where
+ ln_sty = kwargs.pop('linestyle', '')
@NelleV
NelleV Mar 15, 2013 Contributor

I think this variable would benefit from a more explicite name.

@tacaswell
tacaswell Mar 15, 2013 Member

What would be a more explicit name? (I think there is some level of judgement here as I thought that was already a pretty explicit name). I have no problem changing it, I would just like to only change it once ;)

@NelleV
NelleV Mar 15, 2013 Contributor

Maybe something like linestyle if it is not already taken :)

@tacaswell
tacaswell Mar 15, 2013 Member

I guess I am (probably unjustly) paranoid about shadowing/trampling existing variables. How about usr_linestyle which makes me happy and makes it clear that this is the part of the linestyle that the user passed in, not the total linestyle that will be passed to plot

@NelleV
NelleV Mar 15, 2013 Contributor

sounds good !

@NelleV
Contributor
NelleV commented Mar 15, 2013

Apart from my last tiny nitpick, this looks good to me: 👍

@tacaswell
Member

@NelleV done

@tacaswell
Member

I am not sure why it is failing, I will look into this later tonight.

@tacaswell
Member

The failure is due to what looks like a few pixel shift of the entire figure in the png output that I suspect is from the change is c64d0c25668b08cda4c19bb0c3c7ebfa56e47afe (based on the large number of image updates that go along with it).

At any rate, rebased and replaced the offending test image.

@tacaswell
Member

and if I had been thinking I would have also squashed some of those commits out of existence while I was re-writing history, but oh well.

@mdboom
Member
mdboom commented Mar 18, 2013

Nice. The only thing to add is probably a changelog entry to users now they can now do this.

@pelson
Member
pelson commented Mar 19, 2013

👍 Nice work.

@dmcdougall dmcdougall merged commit a844fbb into matplotlib:master Mar 23, 2013

1 check passed

default The Travis build passed
Details
@tacaswell tacaswell deleted the tacaswell:step_linestyle branch Mar 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment