-
Notifications
You must be signed in to change notification settings - Fork 18
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
rework plotting to allow for plot_axes #79
Conversation
Both of us putting thought into this today! Posts with minutes of each other. 😆 For colorbars, try passing if ax is None:
colorbar = plt.colorbar
else:
# might actually need a partial here, if plt.colorbar doesn't have ax/cax params
colorbar = ax.figure.colorbar
cb = colorbar(sm, fraction=0.046, pad=0.04, ax=ax) # maybe cax=ax? See docs on |
The idea above should act as I suggested in #78: defaults to adding a colorbar for each axis, although the user can override with def colorbar(cmap, is_divergent, cbar_min, ax=None):
...
I'll need to write some docs at some point to explain how to use divergent vs. sequential color maps, and why I think there's so much virtue in using the top half of a divergent color map. But this is definitely a more user-friendly way to build a colorbar. The point of all of this is to prep info that gets fed into I also lean toward the overall idea of gathering some of the matplotlib stuff together at some point. In principle, the future might involve non-matplotlib plotting (e.g., interactive Bokeh that tells you more about the contact when you hover). Feel free to move things around if it makes sense to you. |
Thanks both of you for looking into this in detail, and so quickly too! Unfortunately, I'm unable to install that version, I'm still on Python 2.7.16 (for compatibility with my lab's software) and I get this error:
|
Also, regarding #78 @dwhswenson 's option 3 with the kwargs, according to this, it doesn't seem like there would be an issue mixing explicitly named/default kwargs with the arbitrary **kwargs unpacking? |
@nffaruk Unfortunately, I see you are using conda, is there a particular reason why you can't separate the conda environments for your lab software and contact map explorer? If not, you can try the following:
This will make a new conda environment for contact map, if you want to activate it in a new shell you can use
The problem @dwhswenson indicated is that not all valid |
@sroet : This particular problem can be fixed by updating the vendored copy of I don't think we've added anything that breaks Py2 compatibility yet, but that will definitely come soon. |
@dwhswenson any preference on the codeclimate issue? (Function ranged_colorbar has 6 arguments (exceeds 5 allowed) I opted to remove the |
That's fine. Or I'll ignore it, if codeclimate keeps complaining. It is designed to be a function that I can copy into other projects in the future. It does a lot more than what we use. |
awesome, applied the same code. @nffaruk do you mind rerunning the install? |
@dwhswenson this is ready for a review (apparently our current test-suite catches all changes made to the code in this PR) |
Got it to install and it works great, thanks! For sure developers shouldn't have the burden of supporting end of life software and it's straightforward to switch environments, but I was hoping there would be an easy fix considering our PI is a big user of your package (this subplot request came from him) and uses it in conjunction with a bunch of analysis functions from our side. But we will have to get on the inescapable migration to Python 3 soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo in a docstring, otherwise LGTM. I noticed that the colorbars don't go the full height of the plot (compare output of cell 12 and cell 11 in the notebook), but that can be dealt with later.
One other thing: please go ahead and bump the version to 0.6.0.dev0 (in setup.cfg
and ci/conda-recipe/meta.yaml
). This will definitely be part of a 0.6.0 release, not a 0.5.1 release (if I can fix the Travis/autorelease issues for 0.5.1).
contact_map/plot_utils.py
Outdated
@@ -20,8 +21,8 @@ def ranged_colorbar(cmap, norm, cbmin, cbmax, name="Partial Map"): | |||
minimum value for the colorbar | |||
cbmax : float | |||
maximum value for the colorbar | |||
name : str | |||
name for the submap to be created | |||
ax : matplotlib.axes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capitalize: matplotlib.Axes
Yeah, I think this is a difference between "taking space from an existing axes" and "adding a colorbar axes", but not to sure about that. Give me an hour to test something out |
No rush... I probably won't merge this until after 0.5.1 gets released, anyway. I have a few ideas to test that might fix the release process. |
Figured it out: it is due to the changed aspect ratio of the axes (default is 10,8) but for that plot I used (20,6). If I change it to (30,8) it plots as intended again. |
All set ;) |
With 0.5.1 out, I'll go ahead and merge this as the first step to 0.6.0! |
Closes #78
This reworks the plotting of
ContactCount
, it split out the axes plotting code inContactCount.plot_axes()
This also allows users to use
plot_axes
to allow for greater flexibility (like withsubplots
)This now works:
BIG DIFFERENCE betweenplot()
andplot_axes()
: Nocolorbar
forplot_axes()
Colorbars are hard for subplots inmatplotlib
(part of the figure, but also plotted with the lastax
ofsubplots
)An user can add a seperate colorbar to the figure if they want, using any of the answers here.
Edit: current default plots a colorbar in every axes, can be turned off
with_colorbar=False
[API-BREAK] - in
.plot_utils
the call-signature ofranged_colorbar
has changed:- unused kwarg
name
is removed- new kwarg
ax
is added, this is theaxes
that is put intoplt.colorbar( ax=ax)
@nffaruk Would you be able to see if this solves your issue?
You can install this version of the code by running
pip install git+https://github.com/sroet/contact_map.git@allow_fig_ax_kw
preferably in a new
conda
environment (or you might need to uninstall first, depending on how you installed Contact Map Explorer in the first place)