-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
DOC: Plot discrete colormap with proportional colorbar #1930
Conversation
Using 'cbar_kwargs' it is possible to extend the capabilities of colorbar ticks.
Proportional colorbar for discrete colormaps | ||
================================= | ||
|
||
While plotting a discrete colormap you may wish to label every colorbar ticks. By default, the tick labels are limited to a number of 10. |
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.
E501 line too long (137 > 79 characters)
================================= | ||
|
||
While plotting a discrete colormap you may wish to label every colorbar ticks. By default, the tick labels are limited to a number of 10. | ||
However, you can use the ``cbar_kwargs`` keyword to specify the number of ticks. It is also possible to arrange the spacing between ticks if ``levels`` are not regular. |
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.
E501 line too long (168 > 79 characters)
f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(14, 4)) | ||
|
||
# Different levels | ||
levels = [200,210,220,230,240,250,260,270,280,290,320] |
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.
E231 missing whitespace after ','
|
||
""" | ||
|
||
import xarray as xr |
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.
W1618 import missing from __future__ import absolute_import
Apparently we did not successfully disable stickler in doc directories. But please do fix the line-length issue. I don't think using an absolute import would improve clarity here. |
Shortened intro texts.
``spacing`` can be used to draw the ticks proportional too. | ||
""" | ||
|
||
import xarray as xr |
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.
W1618 import missing from __future__ import absolute_import
added absolute_import to make stickler happy, can be removed later.
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.
Thanks! A few small changes and this should be good to go.
# -*- coding: utf-8 -*- | ||
""" | ||
============================================ | ||
Proportional colorbar for discrete colormaps |
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.
Maybe: Control the plot's colorbar
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.
Makes more sense.
============================================ | ||
|
||
Use ``cbar_kwargs`` keyword to specify the number of ticks. | ||
``spacing`` can be used to draw the ticks proportional too. |
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.
... to draw proportional ticks.
Use ``cbar_kwargs`` keyword to specify the number of ticks. | ||
``spacing`` can be used to draw the ticks proportional too. | ||
""" | ||
from __future__ import absolute_import |
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.
Sorry, please ignore our bot on this one: remove this line
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.
The bot has been terminated -- if you merge in master, it should no longer bother you!
# Load the data | ||
air_temp = xr.tutorial.load_dataset('air_temperature') | ||
air = air_temp.air | ||
air2d = air.isel(time=500) |
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.
merge in one line:
air2d = air_temp.air.isel(time=500)
Renamed the script, script info updated.
doc/gallery/control_plot_colorbar.py
Outdated
Use ``cbar_kwargs`` keyword to specify the number of ticks. | ||
``spacing`` can be used to draw proportional ticks.. | ||
""" | ||
import xarray as xr |
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.
W1618 import missing from __future__ import absolute_import
@shoyer Looks like stickler bot is still active. |
Use ``cbar_kwargs`` keyword to specify the number of ticks. | ||
The ``spacing`` kwarg can be used to draw proportional ticks. | ||
""" | ||
import xarray as xr |
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.
W1618 import missing from __future__ import absolute_import
Thanks @paulvija ! |
* Plot discrete colormap with proportional colorbar Using 'cbar_kwargs' it is possible to extend the capabilities of colorbar ticks. * Fixing style errors. * Fixing style errors. * Fixed the line-length issue Shortened intro texts. * added absolute_import added absolute_import to make stickler happy, can be removed later. * Updated script with changes requested Renamed the script, script info updated. * Cosmetic changes
@fmaussion Would the plot image display automatically here or something I have to do at my end? |
Hmm, I'm not sure. Let's see if rebuilding the docs fixes it... If that doesn't work, it might be a good idea to do some tests with a local docs build. |
Using 'cbar_kwargs' it is possible to extend the capabilities of colorbar ticks.