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

ENH: Add baseline feature to stackplot. #1517

Closed
wants to merge 2 commits into from
Closed

ENH: Add baseline feature to stackplot. #1517

wants to merge 2 commits into from

Conversation

Tillsten
Copy link
Contributor

This PR enhances the stacked plot method with some three addition baseline calculations.

All follows from:
http://www.leebyron.com/else/streamgraph/

see the code (bsd) and the paper there.

@Tillsten
Copy link
Contributor Author

To plot an nice example use:

    def layers(n, m):
        def bump(a):
            x = 1 / (.1 + r.random())
            y = 2 * r.random() - .5
            z = 10 / (.1+ r.random())
            for i in range(m):
                w = (i / float(m) - y) * z
                a[i] += x * np.exp(-w*w)
        a=np.zeros((m, n))
        for i in range(n):
            for j in range(5):            
                bump(a[:,i])
        return a 


    d=layers(3,100)
    clf()
    subplot(221)
    stackplot(gca(), range(100), d.T, baseline='zero')
    subplot(222)
    stackplot(gca(), range(100), d.T, baseline='sym')
    subplot(223)
    stackplot(gca(), range(100), d.T, baseline='wiggle')
    subplot(224)
    stackplot(gca(), range(100), d.T, baseline='weighted_wiggle')


# Color between array i-1 and array i
for i in xrange(len(y)-1):
r.append(axes.fill_between(x, y_stack[i,:], y_stack[i+1,:], facecolor=axes._get_lines.color_cycle.next(), **kwargs))
return r
return r
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed (probably accidentally) the new line at the end of this file. Could you add it back in?

@dmcdougall
Copy link
Member

Thanks @Tillsten. I haven't had a chance to play with this yet, I'll give more detailed feedback once I have. At the very least you should check this code adheres to the PEP8 standard, and you should add some image comparison tests for the new functionality.

@Tillsten
Copy link
Contributor Author

@dmcdougall I don't see any PEP8 violations, except the newline issue, maybe you can give me a hint?

I have some questions about the image comparison:
Do i have to include the image itself or will it be generated if not found?

@dmcdougall
Copy link
Member

@Tillsten I wasn't saying there was any, I was just asking you to check :)

When you write the test, run it. The test will fail because there is no baseline image to compare the output images to. The output images from that test run will be used as the baseline images for subsequent tests. I'm not sure that was entirely clear. Let me know if you need more help. Check out the coding guideline if you haven't already.

@Tillsten
Copy link
Contributor Author

@dmcdougall After my last disastrous PR i had my eye on PEP8 :).

So if there no baseline image, a new one will be made? So i have just to make
a simple plot script with the right decorator?

btw, the link to http://matplotlib.org/devel/testing.html#testing does not work.

@Tillsten
Copy link
Contributor Author

Hmm, it seems i can not run the tests without building matplotlib itself, which is hard on my windows machine. I get

  from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
  ImportError: No module named _path

. Can somebody else check and upload the baseline image?

@Tillsten
Copy link
Contributor Author

@dmcdougall except the baseline image issue, i think this one is ready to merge

@Tillsten
Copy link
Contributor Author

anything i can do?

first_line = center - 0.5 * total
y_stack += first_line
else:
raise ValueError('unknown baseline method')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of this exception message, I would include what value was unknown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any kind of standard message for this kind of error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there is no 'standard' message. But a user could easily run into this error by, for example, making a typo in the baseline method name. Perhaps something more informative would be:

'Unknown baseline method %s' % baseline

Or:

'Baseline method %s not recognised. Expected 'zero', 'sym', 'wiggle' or 'weighted_wiggle'

Note, I am not necessarily suggesting the accepted baseline methods are hard-coded into the exception message. There's probably a better way to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmcdougall I think putting the acceptable methods into the message is fine in this case. They will be quite stable and if another method is added it is only a small change.

@Tillsten
Copy link
Contributor Author

I removed the testimage (because i can't build master under my windows installtion) for now to make this PR ready
to merge.

@Tillsten
Copy link
Contributor Author

I suspect the travis failure is not my fault?

@mdboom
Copy link
Member

mdboom commented Jan 10, 2013

Yes -- the Travis failure is a false negative -- that happens all too often unfortunately. I'd prefer to get the test in here before we merge -- I'll try to look into this later today. If we merge without it, let's at least create another issue to track it so we don't forget to put it in.


# Color between x = 0 and the first array.
r.append(axes.fill_between(x, 0, y_stack[0, :],
facecolor=axes._get_lines.color_cycle.next(), **kwargs))
r.append(axes.fill_between(x, first_line, y_stack[0,:],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 compliance: there is a space missing between , and :

@NelleV
Copy link
Member

NelleV commented Jan 11, 2013

@Tillsten I've written down the pep8 problems. In order to more easily see those, you can use the tool pep8, or the tool flake8 (I use flake8 because it also underlies pyflakes problems, which is very useful). If you use vim or emacs, you can easily have flake8 run automatically on your code.

@Tillsten
Copy link
Contributor Author

@NelleV i used a pyflakes, but i think i lost my last (only pep8) commit on rebase.

@@ -25,6 +25,16 @@ def stackplot(axes, x, *args, **kwargs):

Keyword arguments:

*baseline* : ['zero', 'sym', 'wiggle', 'weighted_wiggle']
Method use to calculate to baseline. 'zero' is just a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am misunderstanding, but shouldn't it be "Method used to calcule the baseline."?

@mdboom
Copy link
Member

mdboom commented Jan 16, 2013

This needs a test and a CHANGELOG entry.

@Tillsten
Copy link
Contributor Author

@mdboom This had a test, my problem is that i am under windows and i am not able to run master. So uploading a
comparsion image with this PR dont make much sense. Because nobody was able to help me, i removed the test from this PR to make it ready to merge.

@dmcdougall
Copy link
Member

@Tillsten I can make a PR against your branch to add a test for you. Or I can fork your branch directly and create a new PR. Any preference?

@Tillsten
Copy link
Contributor Author

@dmcdougall Just fork it (and possible take care of the spelling errors). i am not at the right pc at the moment.
You can use the code in the first post to generate a passable image (of course, set the seed).

@dmcdougall dmcdougall mentioned this pull request Jan 16, 2013
@dmcdougall
Copy link
Member

See #1671.

@Tillsten
Copy link
Contributor Author

@dmcdougall Thanks! closing this one.

@Tillsten Tillsten closed this Jan 16, 2013
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

Successfully merging this pull request may close these issues.

None yet

5 participants