Repository navigation
Colorbar only tut - #8600
Colorbar only tut#8600
Conversation
story645
left a comment
There was a problem hiding this comment.
also cc @choldgraf since he's been kinda lead on documentation lately.
| Customized Colorbars Tutorial | ||
| ============================= | ||
|
|
||
| This tutorial shows how to build colorbars without an attached mappable. |
There was a problem hiding this comment.
Since this is a tutorial, use something less jargony than mappable. Without an attached plot maybe?
There was a problem hiding this comment.
Mappable replaced by plot.
| import matplotlib.pyplot as plt | ||
| import matplotlib as mpl | ||
|
|
||
| fig = plt.figure(figsize=(8, 3)) |
There was a problem hiding this comment.
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.
Even figsize is not necessary so removed that too.
| # --------------------------- | ||
| # | ||
| # The second example illustrates the use of a ListedColormap which generates | ||
| # colormap from a set of listed colors, a BoundaryNorm which generates a |
| # | ||
| # 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 |
| # 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.
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.
I am guessing here that 'Now in the third example' is needed to be replaced by 'Here'. Correct me if I am wrong.
| # 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 |
| # ==================== | ||
| # | ||
| # `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.
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.
| # | ||
| # `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 |
| # 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.
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.
What is the name of the color with RGB = (0, 0.4, 1)?
|
|
||
| """ | ||
|
|
||
| ############################################################################### |
There was a problem hiding this comment.
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.
Changed so as to have uniform format in all tutorials.
| # 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.
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)
| # 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.
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.
I wasn't sure where could it point to so gave a link to colorbar api.
| # 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.
":class:matplotlib.colors.ListedColormap"
There was a problem hiding this comment.
(and elsewhere in any point that we refer to a specific class / function / module in MPL)
| cb3.set_label('Custom extension lengths, some other units') | ||
|
|
||
| plt.tight_layout() | ||
| plt.show() |
There was a problem hiding this comment.
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.
Thanks for pointing it out. My text editor was inserting a new line on save, fixed now.
There was a problem hiding this comment.
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.
oops - yes I meant we wanted the new line, sorry about the confusion
|
@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. |
| # 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.
"...length of the interior colors, use extendfrac='auto'"
|
small point in there about using double backticks for the kwarg but other than that LGTM |
| # 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.
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 :-/
| # 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.
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 |
PR Summary
Trying to convert colorbar_only example to tutorial.
cc @choldgraf
#8561
PR Checklist