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

feat: MatPlot updates (Updated version of #337) #636

Merged
merged 8 commits into from
Jun 21, 2017

Conversation

nulinspiratie
Copy link
Contributor

Fixes #257, and replaces #337 since that branch was deleted. Also includes fixes proposed in #615.

Changes proposed in this pull request:

  • Interpolation of x and y coords in pcolormesh. Previously, MatPlot used to ignore edgepoints.This is because MatPlot treats the x and y values as grid corners instead of grid centers. This also resulted in data points being shifted by half a grid. Now the x and y values are transformed to grid corners (which increases their arrays by 1). Doing this allows the edgepoints to be included as well. If the array only contains one element, the grid size cannot yet be determined, and defaults to 1. This also works with non-equidistant setpoints.
  • Args passed in initial instance creation are treated as data that should be plotted on individual subplots. This means that MatPlot(data.arr1, data.arr2) will create two subplots, one for each arr. An arg can also consist of multiple args, in which case they will all be plotted on the same subplot (e.g. MatPlot([data.arr1, data.arr2], data.arr3)` will create two subplots: one for arr1 and arr2, the other for arr3).
  • Easy access to subplots via subplot index (plot[k] is now identical to plot.subplots[k]). The add method is furthermore added to each subplot, meaning that you can now write plot[k].add(data), which is identical to plot.add(data, subplot=k). A consequence is that the method _get_axes is not needed anymore, and is therefore removed.
  • Inferring subplot shape from args unless explicitly provided. MatPlot now has a class attribute max_subplot_columns (=3 by default), which indicates the default maximum number of subplot columns. If one passes 3 args and no subplots kwarg, it will use subplots=(1,3) by default. For 6 args, it will become subplots=(2,3).
  • Inferring figsize from subplots unless explicitly provided. The method default_figsize() returns a default figsize to use depending on the shape of subplots.
  • Scaling of colorbar in pcolormesh
  • Add method tight_layout(), which performs fig.tight_layout() with some extra space at the top for the title. It is called at the end of initialization

@giulioungaretti @jenshnielsen

@nulinspiratie nulinspiratie mentioned this pull request Jun 8, 2017
@nulinspiratie nulinspiratie changed the title MatPlot updates (Updated version of #337) feat: MatPlot updates (Updated version of #337) Jun 8, 2017
nulinspiratie added a commit to nulinspiratie/Qcodes that referenced this pull request Jun 8, 2017

kwargs: with the following exceptions (mostly the data!), these are
passed directly to the matplotlib plotting routine.
`subplot`: the 1-based axes number to append to (default 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default has changed from 1 to 0 and this is now zero based. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry I forgot to mention that. I made that change quite a while ago, but yes it was intentional. I couldn't understand why subplots started at 1, since Python is 0-based. Combining it with subplot indices (plot[idx]), it made more sense to me to use 0-based axes numbers. Do you agree? If so, I could modify the docstring above

Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I agree that it's most logical for all arrays to be 0 indexed. I think the reasoning here is that pyplot.subplot(nml) is 1 indexed, as in pyplot.subplot(211) gives the first subplot of the 2,1 grid. That is an artefact of matplotlibs api being inspired by Matlab.

The biggest worry is that this will break backwards compatibility, @QCoDeS/core any opinion on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right good point. In that case we could opt for the subplot kwarg to still be 1-based, while the indexing to be 0-based, similar to pyplot.add_subplot being 1-based, but the axes in fig, axes=pyplot.subplots() being an array, and hence 0-based. I hope this doesn't add more confusion though

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes that is probably the best even if a bit confusing. It's consistent with matplotlib any way

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also opt for keeping consistency with matplotlib. That way I reckon we confuse the smallest amount of people to the least degree (although confusion is inescapable).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright just added a commit that changed this

@jenshnielsen jenshnielsen merged commit be08c9a into microsoft:master Jun 21, 2017
giulioungaretti pushed a commit that referenced this pull request Jun 21, 2017
Author: Serwan Asaad <[email protected]>

    feat: MatPlot updates (Updated version of #337) (#636)
Dominik-Vogel pushed a commit to Dominik-Vogel/Qcodes that referenced this pull request Aug 9, 2017
* Copied MatPlot changes from Nulinspiratie fork

* fix: Forgot a call to _get_axes

* refactor: made subplot kwarg 1-based

* refactor: made default_figsize static, remove trailing white spaces

* fix: kwargs are also passed if there are multiple args provided.

* fix: also allow multiple subargs as first arg

* fix: forgot to change default subplot=1 in update_plot
peendebak pushed a commit to VandersypenQutech/Qcodes that referenced this pull request Aug 11, 2017
* Copied MatPlot changes from Nulinspiratie fork

* fix: Forgot a call to _get_axes

* refactor: made subplot kwarg 1-based

* refactor: made default_figsize static, remove trailing white spaces

* fix: kwargs are also passed if there are multiple args provided.

* fix: also allow multiple subargs as first arg

* fix: forgot to change default subplot=1 in update_plot
@nulinspiratie nulinspiratie deleted the feature/matplot_upgrades branch September 26, 2017 08:57
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.

MatPlot bug
3 participants