Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Step linestyle #1802

Merged
merged 7 commits into from

5 participants

@tacaswell
Owner

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.

lib/matplotlib/tests/test_axes.py
@@ -1187,3 +1187,30 @@ def test_eb_line_zorder():
if __name__=='__main__':
@NelleV Collaborator
NelleV added a note

You need to remove this.

@tacaswell Owner

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 Collaborator
NelleV added a note

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 Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 Collaborator
NelleV added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@NelleV NelleV commented on the diff
lib/matplotlib/tests/test_axes.py
((11 lines not shown))
+ 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 Collaborator
NelleV added a note

There should be only two blank lines here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/matplotlib/tests/test_axes.py
((15 lines not shown))
+ 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 Collaborator
NelleV added a note

There should be a space after ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tacaswell
Owner

Sorry about the style issues.

@tacaswell
Owner

The 2.6 failure is related to pip and pyparsing

@mdboom
Owner

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

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 Collaborator
NelleV added a note

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

@tacaswell Owner

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 Collaborator
NelleV added a note

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

@tacaswell Owner

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 Collaborator
NelleV added a note

sounds good !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@NelleV
Collaborator

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

@tacaswell
Owner

@NelleV done

@tacaswell
Owner

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

@tacaswell
Owner

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
Owner

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
Owner

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

@pelson
Collaborator

:+1: Nice work.

@dmcdougall dmcdougall merged commit a844fbb into matplotlib:master

1 check passed

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

    Changed `step` to append the user specified `linestyle` onto the

    tacaswell authored
    `linestyle` that is passed to `plot` instead of silently ignoring it.
  3. @tacaswell

    pep8 fixes

    tacaswell authored
  4. @tacaswell
  5. @tacaswell

    fixed random text insertion

    tacaswell authored
  6. @tacaswell
Commits on Mar 19, 2013
  1. added CHANGELOG entry for this feature.

    Thomas A Caswell authored
Something went wrong with that request. Please try again.