-
-
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
Changes from 1 commit
f8d96be
d6b49b9
1a2b58a
a875825
c7f582c
00e7d0f
3c19954
6ae3c6f
2996c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,31 +3,26 @@ | |
Customized Colorbars Tutorial | ||
============================= | ||
|
||
This tutorial shows how to build colorbars without an attached mappable. | ||
This tutorial shows how to build colorbars without an attached plot. | ||
|
||
""" | ||
|
||
############################################################################### | ||
# Customized Colorbars | ||
# ==================== | ||
# | ||
# `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 | ||
# colormap and does not need a mappable object like an image. In this tutorial | ||
# we will explore what can be done with standalone colorbar. | ||
# ColorbarBase derives from ScalarMappable and puts a colorbar in a specified | ||
# axes, so it has everything needed for a standalone colorbar. It can be used | ||
# as is to make a colorbar for a given colormap and does not need a mappable | ||
# 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 axis at position | ||
# [left, bottom, width, height] where all quantities are in fractions of figure | ||
# width and height. | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
import matplotlib.pyplot as plt | ||
import matplotlib as mpl | ||
|
||
fig = plt.figure(figsize=(8, 3)) | ||
ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15]) | ||
ax2 = fig.add_axes([0.05, 0.475, 0.9, 0.15]) | ||
ax3 = fig.add_axes([0.05, 0.15, 0.9, 0.15]) | ||
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3) | ||
|
||
############################################################################### | ||
# Basic continuous colorbar | ||
|
@@ -51,9 +46,9 @@ | |
# Discrete intervals colorbar | ||
# --------------------------- | ||
# | ||
# The second example illustrates the use of a ListedColormap which generates | ||
# The second example illustrates the use of a ListedColormap which generates a | ||
# 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
# colormap index based on discrete interval and extended ends to show the | ||
# colormap index based on discrete intervals and extended ends to show the | ||
# "over" and "under" value colors. Over and under are used to display data | ||
# 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. | ||
|
@@ -87,10 +82,10 @@ | |
# Colorbar with custom extension lengths | ||
# -------------------------------------- | ||
# | ||
# 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 | ||
# Here 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 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 commentThe 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 commentThe 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 commentThe 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)? |
||
[1., .8, 0.], [1., .4, 0.]]) | ||
|
@@ -109,4 +104,5 @@ | |
orientation='horizontal') | ||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 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.
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 codeThere 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.