8000 Colorbar only tut by patniharshit · Pull Request #8600 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 9 commits into from
May 29, 2017
Prev Previous commit
Next Next commit
Changes in colorbar_only tutorial documentation
  • Loading branch information
patniharshit committed May 11, 2017
commit 1a2b58abca64976aa89ccaf97e4b229bd722ca28
34 changes: 15 additions & 19 deletions tutorials/colors/colorbar_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""

###############################################################################
Copy link
Contributor

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

Copy link
Contributor Author

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.

# 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

three axes

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

generates a

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Expand Down Expand Up @@ -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.],
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Totally agree.

Copy link
Contributor Author

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)?

[1., .8, 0.], [1., .4, 0.]])
Expand All @@ -109,4 +104,5 @@
orientation='horizontal')
cb3.set_label('Custom extension lengths, some other units')

plt.tight_layout()
plt.show()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now.

0