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

Unable to add color bar to heat map or interact plot without using pyplot API #528

Closed
durden opened this issue Apr 28, 2015 · 6 comments
Closed

Comments

@durden
Copy link

durden commented Apr 28, 2015

I'm using the corrplot function and everything works great if I use the pyplot interface for matplotlib. This requires the code surrounding the call to corrplot to do some calls to plt.sca, etc. to manipulate the state in pyplot so everything works. However, there's an ax argument that almost eliminates the need for the caller to use the pyplot interface at all. Yet the color bar is added with the pyplot interface explicitly.

I really like that if I do not pass in an ax argument the pyplot interface is the fallback, i.e corrplot calls plt.gca to get an axes. Could this same strategy be applied to the figure? For example, corrplot could take an optional figure argument and fallback to plt.gcf if one isn't passed in. This would allow callers to use the OOP interface with matplotlib or the pyplot interface.

Does the seaborn project have a guiding principle on when/when not to use the pyplot interface? I tend to avoid that if possible because I usually build stand-alone applications with matplotlib stuff embedded in Qt widgets. So, maybe my use-case is more rare.

Finally, I looked around in the linearmodels.py file for other uses of the pyplot interface and found very few. Maybe some of those uses are strictly necessary; I didn't look too closely. I did notice that the interactplot function has the same color bar issue as corrplot because it uses plt.colorbar as well.

@mwaskom
Copy link
Owner

mwaskom commented Apr 28, 2015

Sorry I don't actually understand what the issue is?

@durden
Copy link
Author

durden commented Apr 28, 2015

I tested out adding the optional figure argument and things seemed to work in my small test case. I could take a stab at changing this if it seems like something that stays in line with the project's stance on the pyplot interface. Also, I haven't used seaborn enough yet to know if added this argument to one or two functions violates some consistent APIs across the project.

@durden
Copy link
Author

durden commented Apr 28, 2015

Sorry, maybe I'm not clear. The issue is that I have to use the pyplot interface to use a colobar with the corrplot function because the underlying seaborn code uses plt.colorbar instead of whatever figure I want. So if I'm not using pyplot then I cannot tell seaborn which figure to draw the color bar on to.

@durden
Copy link
Author

durden commented Apr 28, 2015

Here's the line of code I'm referring to, maybe that will help.

I want to pass in a specific figure to put the color bar on to since I'd prefer to not use the pyplot api. The function allows for me to pass in my own axes object but not my own figure object.

@mwaskom
Copy link
Owner

mwaskom commented Apr 30, 2015

I think I see now. I don't think those functions need a fig parameter, but it would be better to use the ax.fig.colorbar() method. I think this is what happens in heatmap (where you can also pass a specific colorbar axes. BTW I think corrplot is likely to be deprecated soon anyway in favor of heatmap, which is more flexible and robust. So you might try switching to that for your application.

@durden
Copy link
Author

durden commented Apr 30, 2015

Good point on using heatmap. I've switched to using heatmap and since corrplot will be deprecated so use in doing any additional work on it.

Just for anyone else who runs into something similar, switching to heatmap caused me to run into another error when using not using pyplot. So, I'm still using pyplot, which is OK. I'm running into a situation similar to this error, which is ultimately because of this matplotlib bug.

@durden durden closed this as completed Apr 30, 2015
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

No branches or pull requests

2 participants