-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pyplot.set_cmap broken #896
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
Conversation
You change makes a lot of sense to me. What doesn't make a lot of sense is the current behaviour of allowing |
Not to justify the current behavior, but I think it comes from http://www.mathworks.com/help/techdoc/ref/colormap.html It's not very clear from the description, but it is clear from the examples further down that that is how it's intended to work. I don't think we can change this without breaking backward compatibility, as you say. It is strange how it sort of works "retroactively" like that. Maybe we could add a kwarg "update_current_image" (or something shorter) that defaults to True? Ok, that's not a great idea, either, but it's the best I can think of right now... |
Playing devil's advocate, I guess the question then is whether pyplot is a "warts and all" reflection of matlab's core api :-) |
No -- there's lots of places where matplotlib has chosen to deviate from matlab's API -- I was just giving some history. The problem is that it's worked this way for so long, it's bound to break people's scripts. We can deprecate for a release, and then fix this in a subsequent release, however. |
This pull request looks good; the discussion relates to a possible future pull request. |
Hi, sorry I am having the same issue if I do:
nothing happens. However if I change the colormap with
then the colors are changed as intended. The reason is that pl.set_cmap is defined in pyplot.py but im.set_cmap uses set_cmap defined in matplotlib/cm.py, Now I am new to matplotlib, but the behaviour seem broken to me. Is this really an issue to be reopened, or am I doing something wrong? Thanks for the help! Luca |
Luca, |
Thanks Eric ( @efiring ), In the tutorial however (http://matplotlib.org/users/image_tutorial.html)
And the image is shown with a different colormap, without mentioning the call to pylab.draw() Just out of curiosity is there a way to have the draw() performed automatically when some property is modified? Thanks again for the help, and sorry if I opened an issue when not needed. Cheers, |
Sadly not. The methods are not wired up that way (they can't know about the pyplot module without causing some nasty circularity). For example, compare the axes.plot method vs the pyplot.plot function (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_axes.py#L1334 vs https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/pyplot.py#L2995). You will see that the method call just adds the appropriate Artist objects (the lines etc that get drawn) whereas the pyplot function does this + triggers a re-draw if necessary.
Interesting. You are right. The reason this works is that the tutorial is written in the perspective of an IPython user, which will plot the last object in the prompt (I think - I've not actually tested that).
No worries. |
Hi Phil, As of the tutorial: I have run the code in the tutorial using Ipython 1.1.0 Thanks again for the help and explanations, Cheers, On 24 September 2013 08:41, Phil Elson notifications@github.com wrote:
Luca Cerone Tel: +447585611951 |
With at least matplotlib 1.1.1rc and above (the one in Ubuntu 12.04 LTS), the following code does not work, while it worked in at least matplotlib 0.99.1.1 and below (the one in Ubuntu 10.04 LTS):
The following code works in both versions of matplotlib:
The attached pull request restores the behavior of earlier matplotlib versions, consistent with the docstring of pyplot.set_cmap.
Background information: In the current version of matplotlib, pyplot.set_cmap throws a RuntimeError('You must first define an image, eg with imshow') when pyplot.gci() returns None. This is wrong, as the documentation explicitly states that it sets "the default colormap" and only applies it "to current image if any".
Of course, set_cmap is not needed in the example above, but it's terribly useful for colormaps that do not have a shortcut method (such as 'binary').