Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Refactor plots2d #1317

Merged
merged 51 commits into from
Jun 21, 2018
Merged

Refactor plots2d #1317

merged 51 commits into from
Jun 21, 2018

Conversation

cwehmeyer
Copy link
Member

This PR refactors the plots2d module:

  • auxiliary functions allow to make custom plots easily
  • new plotting functions (plot_density, plot_free_energy_new, plot_contour) with more control (e.g. color bars)
  • old plotting functions retain signatures and behaviour but use new implementation

@@ -16,6 +16,8 @@ Changelog
- msm: fixed serialization of BayesianHMSM, if initialized with a ML-HMSM. #1283
- base: require at least tqdm >= 4.23, because of an API change. #1292, #1293
- plots: fixed minor bug in plot_network (state_labels=None would not work). #1306
- plots: refactored plots2d
Copy link
Member

Choose a reason for hiding this comment

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

this message is kind of uninformative to the user. I would state, that the gca behaviour has changed etc.

@@ -121,23 +114,27 @@ def plot_free_energy(xall, yall, weights=None, ax=None, nbins=100, ncountours=10
weights : ndarray(T), default = None
sample weights. By default all samples have the same weight
ax : matplotlib Axes object, default = None
the axes to plot to. When set to None the default Axes object will be used.
the axes to plot to. When set to None the default Axes object
will be used.
nbins : int, default=100
number of histogram bins used in each dimension
ncountours : int, default=100
number of contours used
offset : float, default=0.1
Copy link
Member

Choose a reason for hiding this comment

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

default is -1 now.

@@ -156,33 +153,403 @@ def plot_free_energy(xall, yall, weights=None, ax=None, nbins=100, ncountours=10
ax : Axes object containing the plot

"""
import matplotlib.pylab as _plt
#import matplotlib.pylab as _plt
Copy link
Member

Choose a reason for hiding this comment

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

delete me

logscale=logscale)


def plot_free_energy_new(
Copy link
Member

Choose a reason for hiding this comment

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

what is actually the difference to the old method? Can we decide to have only one or are they fundamentally different?
A short line in the docstring what this method does different would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

The new plotting functions always return fig, ax, cbar while the old functions return either fig, ax or just ax. Further, plot_free_energy has a parameter typo (countour) which has been fixed in the new function.

I would love to immediately replace everything with the new functions but this would slightly break the API.

Copy link
Member

Choose a reason for hiding this comment

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

We could have a legacy switch parameter to steer the old or new behaviour, but this would convolute the code a bit. I think we should deprecate the old function and promote the new one, shouldn't we?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, indeed. I don't think functions would be too convoluted, though. Using a legacy switch is a good idea!

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to conserve the sequence of named parameters in legacy mode?

Copy link
Member

@marscher marscher left a comment

Choose a reason for hiding this comment

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

Thank you very much for cleaning this up! Especially not using gca in cases where it is inappropriate is a big win.

@codecov
Copy link

codecov bot commented Jun 18, 2018

Codecov Report

Merging #1317 into devel will increase coverage by 0.4%.
The diff coverage is 95.72%.

Impacted file tree graph

@@            Coverage Diff            @@
##            devel    #1317     +/-   ##
=========================================
+ Coverage   91.64%   92.05%   +0.4%     
=========================================
  Files         223      224      +1     
  Lines       24756    26095   +1339     
=========================================
+ Hits        22687    24021   +1334     
- Misses       2069     2074      +5
Impacted Files Coverage Δ
pyemma/plots/tests/test_plots2d.py 100% <100%> (ø) ⬆️
pyemma/plots/__init__.py 100% <100%> (ø) ⬆️
pyemma/plots/plots1d.py 88.09% <90%> (+9.52%) ⬆️
pyemma/plots/tests/test_plots1d.py 95.83% <93.33%> (-4.17%) ⬇️
pyemma/plots/plots2d.py 94.16% <94.82%> (-0.93%) ⬇️
pyemma/msm/estimators/maximum_likelihood_hmsm.py 83.48% <0%> (-3.13%) ⬇️
pyemma/coordinates/tests/util.py 97.4% <0%> (-2.6%) ⬇️
pyemma/coordinates/data/sources_merger.py 93.65% <0%> (-1.35%) ⬇️
pyemma/util/contexts.py 83.82% <0%> (-1.18%) ⬇️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f412fa8...4b66310. Read the comment docs.

@marscher
Copy link
Member

marscher commented Jun 18, 2018 via email

@thempel
Copy link
Member

thempel commented Jun 19, 2018

For plot_density(), I get different behavior if using logscale or not. Logscale produces a discrete colormap which is otherwise continuous. Was that intended?

Adjust levels to be equally fine in both cases
@thempel
Copy link
Member

thempel commented Jun 19, 2018

@cwehmeyer we discussed that it is potentially useful to have access to colormap or mappable. Since I found it a bit inconsistent to return either the colormap or the mappable, depending on the kwargs, they are now written into a dictionary and returned together. Otherwise, larger customized plots might break down if somebody chooses to alter some of the plot options. I'm not completely happy with it though; if you have a better idea feel free to implement it.

@cwehmeyer cwehmeyer requested a review from thempel June 19, 2018 21:12
@thempel
Copy link
Member

thempel commented Jun 21, 2018

Thx @cwehmeyer. Can you add a line about the kwargs (i.e. what function they are passed to) to the docstrings?

@cwehmeyer
Copy link
Member Author

@thempel: done.

@cwehmeyer cwehmeyer merged commit 22bebd0 into devel Jun 21, 2018
@cwehmeyer cwehmeyer deleted the refactor_plots2d branch June 21, 2018 10:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants