-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Colorbar only tut #8600
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
Colorbar only tut #8600
Conversation
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.
also cc @choldgraf since he's been kinda lead on documentation lately.
tutorials/colors/colorbar_only.py
Outdated
Customized Colorbars Tutorial | ||
============================= | ||
|
||
This tutorial shows how to build colorbars without an attached mappable. |
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.
Since this is a tutorial, use something less jargony than mappable. Without an attached plot maybe?
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.
Mappable replaced by plot.
tutorials/colors/colorbar_only.py
Outdated
import matplotlib.pyplot as plt | ||
import matplotlib as mpl | ||
|
||
fig = plt.figure(figsize=(8, 3)) |
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.
I wonder if you can get away with this since axes stuff isn't the point of this tutorial:
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, figsize=(8,3))
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.
Even figsize is not necessary so removed that too.
tutorials/colors/colorbar_only.py
Outdated
# --------------------------- | ||
# | ||
# The second example illustrates the use of a ListedColormap which generates | ||
# colormap from a set of listed colors, a BoundaryNorm which generates a |
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.
generates a
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.
Done.
tutorials/colors/colorbar_only.py
Outdated
# | ||
# The second example illustrates the use of a ListedColormap which generates | ||
# colormap from a set of listed colors, a BoundaryNorm which generates a | ||
# colormap index based on discrete interval and extended ends to show the |
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.
discrete intervals
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.
Done.
tutorials/colors/colorbar_only.py
Outdated
# Colorbar with custom extension lengths | ||
# -------------------------------------- | ||
# | ||
# Now in the third example we illustrate the use of custom length 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.
Here we illustrate the use of custom length colorbar extensions. (They're used on both discrete and continuous colorbars.)
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.
I am guessing here that 'Now in the third example' is needed to be replaced by 'Here'. Correct me if I am wrong.
tutorials/colors/colorbar_only.py
Outdated
# Now in the third example we illustrate the use of custom length colorbar | ||
# extensions, used on a colorbar with discrete intervals. Here we pass colors | ||
# as RGB triplet. To make the length of each extension the same as the length | ||
# of the interior colors pass extendfrac argument as auto |
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.
pass the extendfrac argument
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.
Done.
tutorials/colors/colorbar_only.py
Outdated
# ==================== | ||
# | ||
# `matplotlib.colorbar.ColorbarBase` derives from `ScalarMappable` and puts a | ||
# colorbar in specified axes, it is the base class with standalone 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.
I think the original is clearer:
ColorbarBase derives from ScalarMappable and puts a colorbar in a specified axes, so it has everything needed for a standalone 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.
Changed.
tutorials/colors/colorbar_only.py
Outdated
# | ||
# `matplotlib.colorbar.ColorbarBase` derives from `ScalarMappable` and puts a | ||
# colorbar in specified axes, it is the base class with standalone colorbar | ||
# drawing functionality. It can be used as-is to make a colorbar for a given |
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.
no dash in as is
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.
Dash removed.
tutorials/colors/colorbar_only.py
Outdated
# the length of each extension the same as the length of the interior colors | ||
# pass the extendfrac argument as auto. | ||
|
||
cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], |
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.
Instead of passing color in RGB format, I feel it will be more clear if colors are referenced by name?
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.
Totally agree.
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.
What is the name of the color with RGB = (0, 0.4, 1)?
tutorials/colors/colorbar_only.py
Outdated
|
||
""" | ||
|
||
############################################################################### |
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.
not a big deal but you technically don't need to be commenting out lines here, just extend the """
up until the first bit of code
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.
Changed so as to have uniform format in all tutorials.
tutorials/colors/colorbar_only.py
Outdated
# object like an image. In this tutorial we will explore what can be done with | ||
# standalone colorbar. | ||
# | ||
# We will start by making a figure of desired size and adding thress 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.
three
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.
Is ScalarMappable
something we can link to via :mod:
? If so we should do it, it's going to be unclear to most people what this is (if it's important)
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.
Done.
tutorials/colors/colorbar_only.py
Outdated
# will be used. Then create the colorbar by calling `ColorbarBase` and | ||
# specify axis, colormap, norm and orientation as parameters. Here we create | ||
# a basic continuous colorbar with ticks and labels. There are many more kwargs | ||
# which can be used to further modify the 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.
In these kinds of sentences I like to say something like "for more examples, see ". Something worth thinking of inserting where reasonable!
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.
I wasn't sure where could it point to so gave a link to colorbar api.
tutorials/colors/colorbar_only.py
Outdated
# outside of the normalized [0,1] range. Here we pass colors as gray shades as | ||
# a string encoding a float in the 0-1 range. | ||
# | ||
# If a ListedColormap is used, the length of the bounds array must be |
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.
":class:matplotlib.colors.ListedColormap
"
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.
(and elsewhere in any point that we refer to a specific class / function / module in MPL)
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.
Done.
tutorials/colors/colorbar_only.py
Outdated
cb3.set_label('Custom extension lengths, some other units') | ||
|
||
plt.tight_layout() | ||
plt.show() |
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.
stupid question but is there an extra line at the bottom? I think that's best practices but not sure what MPL does as a standard.
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 for pointing it out. My text editor was inserting a new line on save, fixed now.
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.
There should be a newline at the end. If GitHub has that little red symbol on the last line, it means there isn't one.
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.
oops - yes I meant we wanted the new line, sorry about the confusion
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.
Fixed now.
@patniharshit looking really nice! thanks for putting this together. I've got a couple quick points in there but I think it's looking great. |
tutorials/colors/colorbar_only.py
Outdated
# the length of each extension the same as the length of the interior colors | ||
# pass the extendfrac argument as auto. | ||
# colorbar with discrete intervals. To make the length of each extension the | ||
# same as the length of the interior colors pass the *extendfrac* argument as |
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.
"...length of the interior colors, use extendfrac='auto'
"
small point in there about using double backticks for the kwarg but other than that LGTM |
tutorials/colors/colorbar_only.py
Outdated
# same as the length of the interior colors pass the *extendfrac* argument as | ||
# *auto*. | ||
# colorbar with discrete intervals. To make the length of each extension same | ||
# as the length of the interior colors, use extendfrac='auto'. |
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 to be picky, but I meant adding in double backticks around it, so:
``extendfrac='auto'``
so that it will render like: extendfrac='auto'
instead of "extendfrac='auto'"
I'd edit the branch if I could but I don't have commit rights :-/
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.
Fixed.
tutorials/colors/colorbar_only.py
Outdated
@@ -85,7 +85,7 @@ | |||
# | |||
# Here we illustrate the use of custom length colorbar extensions, used on a | |||
# colorbar with discrete intervals. To make the length of each extension same | |||
# as the length of the interior colors, use extendfrac='auto'. | |||
# as the length of the interior colors, use ``extendfrac='auto'``. |
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.
actually do you think you could make this triple backticks?
...JK, this PR looks good to me :)
Whats the issue here? Why check is failing? |
Check out the logs in travis: https://travis-ci.org/matplotlib/matplotlib/jobs/231794760 One drawback of sphinx-gallery is that it collects the figure each time it hits another RST block, so you need to re-do |
Looks like tests are passing. @story645 do you know if there's a build that generates the website for us? E.g., MNE uses |
Just removed a line in comments which read like draw a figure and three axes. It lost its value after we switched to making seperate fig and axis in each rst block instead of making three axes initially. |
Sorry @choldgraf dunno. I know at least one of the tests builds docs, but dunno which one it renders. Maybe @tacaswell can answer this question? |
There are two builds that run the docs, but unfortunately do not upload them anywhere. Travis doesn't hold artifacts though it can go to S3, but I think no-one remembers the key for it... |
@QuLogic I've found it really useful for building docs, particularly when building them locally is non-trivial (as it is with MPL). I can ask the MNE dev that set it up for us if they can explain how tough it was, in case it'd be useful for MPL...lemme know! Otherwise, this PR looks good to me |
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!
PR Summary
Trying to convert colorbar_only example to tutorial.
cc @choldgraf
#8561
PR Checklist