Skip to content

Add figsize, size, and aspect arguments to plotting methods #1168

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

Merged
merged 4 commits into from
Dec 18, 2016

Conversation

fmaussion
Copy link
Member

Extends and finishes #637

I chose to keep seaborn's convention for two reasons:

  • it doesn't break existing code
  • now that figsize is also available, I expect the size and aspect kwargs to be less used in non-facetgrid plots

Closes #897

@fmaussion
Copy link
Member Author

After having another look, facetgrid should probably also accept a figsize kwarg...

@fmaussion
Copy link
Member Author

OK, this should be ready for review now

vmin=cmap_params['vmin'],
vmax=cmap_params['vmax'],
**kwargs)
if 'imshow' == plotfunc.__name__ and isinstance(aspect, basestring):
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to avoid this special case, and simply not pass aspect on to imshow. Xarray imshow is already overloaded to display in data coordinates (not pixels) so I think this is pretty reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I still have to catch this possibility though, otherwise the error message is not very informative

Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify -- what happens if you try write array.plot.imshow(aspect=2)?

I think this should probably result in a plot with the same figure size as array.plot.contourf(aspect=2).

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, sorry. Both methods will raise the same ValueError if called with aspect=2:

ValueError: cannot provide `aspect` argument without `size`

The point of this line is to provide a more informative error message when users try to set aspect='equal', as in this test for example. If you're happy with the message above I can remove this block.

Copy link
Member

Choose a reason for hiding this comment

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

Oh OK, I was confused about this :). I agree, this makes complete sense.

# create a dummy figure so sphinx plots everything below normally
plt.figure()

This feature also works with :ref:`plotting.faceting`.
Copy link
Member

Choose a reason for hiding this comment

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

I think figsize refers to the entire figure when used with faceting, but size only refers to a single panel. We should either make that consistent (both referring to single panels?) or note the difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that figsize should always refer to the entire figure, as in matplotlib. I added a note to the docs

@fmaussion
Copy link
Member Author

OK, this should be ready for another round of reviews

**kwargs)
if 'imshow' == plotfunc.__name__ and isinstance(aspect, basestring):
# forbid usage of mpl strings
raise ValueError("plt.imshow's `aspect` kwarg is not available " \
Copy link
Member

Choose a reason for hiding this comment

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

Just use implicitly string concatenation here instead of writing \ (you almost never want/need to actually use \)

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.

2 participants