From f8d96be6d5ea1f5da396cf5c04a048633f34cc4c Mon Sep 17 00:00:00 2001 From: patniharshit Date: Wed, 10 May 2017 02:23:13 +0530 Subject: [PATCH 1/9] Convert colorbar_only example to tutorial --- examples/api/colorbar_only.py | 91 ++++++++++++++++-------- tutorials/colors/colorbar_only.py | 112 ++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 28 deletions(-) create mode 100644 tutorials/colors/colorbar_only.py diff --git a/examples/api/colorbar_only.py b/examples/api/colorbar_only.py index a31600a600b1..c65a9569b319 100644 --- a/examples/api/colorbar_only.py +++ b/examples/api/colorbar_only.py @@ -1,60 +1,97 @@ -''' -==================== -Customized colorbars -==================== +""" +============================= +Customized Colorbars Tutorial +============================= -This example shows how to build colorbars without an attached mappable. -''' +This tutorial shows how to build colorbars without an attached mappable. + +""" + +############################################################################### +# 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. +# +# 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. import matplotlib.pyplot as plt import matplotlib as mpl -# Make a figure and axes with dimensions as desired. 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]) -# Set the colormap and norm to correspond to the data for which -# the colorbar will be used. +############################################################################### +# Basic continuous colorbar +# ------------------------- +# +# Set the colormap and norm to correspond to the data for which the colorbar +# 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. + cmap = mpl.cm.cool norm = mpl.colors.Normalize(vmin=5, vmax=10) -# ColorbarBase derives from ScalarMappable and puts a colorbar -# in a specified axes, so it has everything needed for a -# standalone colorbar. There are many more kwargs, but the -# following gives a basic continuous colorbar with ticks -# and labels. cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, orientation='horizontal') cb1.set_label('Some Units') -# The second example illustrates the use of a ListedColormap, a -# BoundaryNorm, and extended ends to show the "over" and "under" -# value colors. +############################################################################### +# Discrete intervals colorbar +# --------------------------- +# +# 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 +# "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. +# +# If a ListedColormap is used, the length of the bounds array must be +# one greater than the length of the color list. The bounds must be +# monotonically increasing. +# +# This time we pass some more arguments in addition to previous arguments to +# ColorBase. For the out-of-range values to display on the colorbar, we have to +# use the extend keyword argument. To use 'extend', you must specify two extra +# boundaries. Finally spacing argument ensures that intervals are shown on +# colorbar proportionally. + cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c']) cmap.set_over('0.25') cmap.set_under('0.75') -# If a ListedColormap is used, the length of the bounds array must be -# one greater than the length of the color list. The bounds must be -# monotonically increasing. bounds = [1, 2, 4, 7, 8] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm, - # to use 'extend', you must - # specify two extra boundaries: boundaries=[0] + bounds + [13], extend='both', - ticks=bounds, # optional + ticks=bounds, spacing='proportional', orientation='horizontal') cb2.set_label('Discrete intervals, some other units') -# The third example illustrates the use of custom length colorbar -# extensions, used on a colorbar with discrete intervals. +############################################################################### +# 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 + cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], [1., .8, 0.], [1., .4, 0.]]) cmap.set_over((1., 0., 0.)) @@ -66,9 +103,6 @@ norm=norm, boundaries=[-10] + bounds + [10], extend='both', - # Make the length of each extension - # the same as the length of the - # interior colors: extendfrac='auto', ticks=bounds, spacing='uniform', @@ -76,3 +110,4 @@ cb3.set_label('Custom extension lengths, some other units') plt.show() + diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py new file mode 100644 index 000000000000..9f6896b212b8 --- /dev/null +++ b/tutorials/colors/colorbar_only.py @@ -0,0 +1,112 @@ +""" +============================= +Customized Colorbars Tutorial +============================= + +This tutorial shows how to build colorbars without an attached mappable. + +""" + +############################################################################### +# 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. +# +# 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. + +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]) + +############################################################################### +# Basic continuous colorbar +# ------------------------- +# +# Set the colormap and norm to correspond to the data for which the colorbar +# 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. + +cmap = mpl.cm.cool +norm = mpl.colors.Normalize(vmin=5, vmax=10) + +cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, + norm=norm, + orientation='horizontal') +cb1.set_label('Some Units') + +############################################################################### +# Discrete intervals colorbar +# --------------------------- +# +# 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 +# "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. +# +# If a ListedColormap is used, the length of the bounds array must be +# one greater than the length of the color list. The bounds must be +# monotonically increasing. +# +# This time we pass some more arguments in addition to previous arguments to +# ColorBase. For the out-of-range values to display on the colorbar, we have to +# use the extend keyword argument. To use 'extend', you must specify two extra +# boundaries. Finally spacing argument ensures that intervals are shown on +# colorbar proportionally. + +cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c']) +cmap.set_over('0.25') +cmap.set_under('0.75') + +bounds = [1, 2, 4, 7, 8] +norm = mpl.colors.BoundaryNorm(bounds, cmap.N) +cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, + norm=norm, + boundaries=[0] + bounds + [13], + extend='both', + ticks=bounds, + spacing='proportional', + orientation='horizontal') +cb2.set_label('Discrete intervals, some other units') + +############################################################################### +# 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 + +cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], + [1., .8, 0.], [1., .4, 0.]]) +cmap.set_over((1., 0., 0.)) +cmap.set_under((0., 0., 1.)) + +bounds = [-1., -.5, 0., .5, 1.] +norm = mpl.colors.BoundaryNorm(bounds, cmap.N) +cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, + norm=norm, + boundaries=[-10] + bounds + [10], + extend='both', + extendfrac='auto', + ticks=bounds, + spacing='uniform', + orientation='horizontal') +cb3.set_label('Custom extension lengths, some other units') + +plt.show() From d6b49b9d9f6721f50fcb2c205f46fc1ad838a58a Mon Sep 17 00:00:00 2001 From: patniharshit Date: Wed, 10 May 2017 02:29:17 +0530 Subject: [PATCH 2/9] Move to tutorial directory --- examples/api/colorbar_only.py | 113 ---------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 examples/api/colorbar_only.py diff --git a/examples/api/colorbar_only.py b/examples/api/colorbar_only.py deleted file mode 100644 index c65a9569b319..000000000000 --- a/examples/api/colorbar_only.py +++ /dev/null @@ -1,113 +0,0 @@ -""" -============================= -Customized Colorbars Tutorial -============================= - -This tutorial shows how to build colorbars without an attached mappable. - -""" - -############################################################################### -# 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. -# -# 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. - -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]) - -############################################################################### -# Basic continuous colorbar -# ------------------------- -# -# Set the colormap and norm to correspond to the data for which the colorbar -# 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. - -cmap = mpl.cm.cool -norm = mpl.colors.Normalize(vmin=5, vmax=10) - -cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, - norm=norm, - orientation='horizontal') -cb1.set_label('Some Units') - -############################################################################### -# Discrete intervals colorbar -# --------------------------- -# -# 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 -# "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. -# -# If a ListedColormap is used, the length of the bounds array must be -# one greater than the length of the color list. The bounds must be -# monotonically increasing. -# -# This time we pass some more arguments in addition to previous arguments to -# ColorBase. For the out-of-range values to display on the colorbar, we have to -# use the extend keyword argument. To use 'extend', you must specify two extra -# boundaries. Finally spacing argument ensures that intervals are shown on -# colorbar proportionally. - -cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c']) -cmap.set_over('0.25') -cmap.set_under('0.75') - -bounds = [1, 2, 4, 7, 8] -norm = mpl.colors.BoundaryNorm(bounds, cmap.N) -cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, - norm=norm, - boundaries=[0] + bounds + [13], - extend='both', - ticks=bounds, - spacing='proportional', - orientation='horizontal') -cb2.set_label('Discrete intervals, some other units') - -############################################################################### -# 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 - -cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], - [1., .8, 0.], [1., .4, 0.]]) -cmap.set_over((1., 0., 0.)) -cmap.set_under((0., 0., 1.)) - -bounds = [-1., -.5, 0., .5, 1.] -norm = mpl.colors.BoundaryNorm(bounds, cmap.N) -cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, - norm=norm, - boundaries=[-10] + bounds + [10], - extend='both', - extendfrac='auto', - ticks=bounds, - spacing='uniform', - orientation='horizontal') -cb3.set_label('Custom extension lengths, some other units') - -plt.show() - From 1a2b58abca64976aa89ccaf97e4b229bd722ca28 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Thu, 11 May 2017 11:14:21 +0530 Subject: [PATCH 3/9] Changes in colorbar_only tutorial documentation --- tutorials/colors/colorbar_only.py | 34 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index 9f6896b212b8..614180bf40a8 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -3,7 +3,7 @@ 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. """ @@ -11,23 +11,18 @@ # 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. 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 -# 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.], [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() From a875825bbd43a2758c5946061105554d08ac4ee6 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Fri, 12 May 2017 13:17:46 +0530 Subject: [PATCH 4/9] Changes to colorbar_only tutorial --- tutorials/colors/colorbar_only.py | 79 ++++++++++++++++--------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index 614180bf40a8..739b9535bb1f 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -5,19 +5,18 @@ This tutorial shows how to build colorbars without an attached plot. -""" +Customized Colorbars +==================== -############################################################################### -# Customized Colorbars -# ==================== -# -# 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 thress axes. +:class:`~matplotlib.colorbar.ColorbarBase` derives from +:mod:`~matplotlib.cm.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 three axes. +""" import matplotlib.pyplot as plt import matplotlib as mpl @@ -29,10 +28,11 @@ # ------------------------- # # Set the colormap and norm to correspond to the data for which the colorbar -# 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. +# will be used. Then create the colorbar by calling +# :class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm +# and orientation as parameters. Here we create a basic continuous colorbar +# with ticks and labels. More information on colorbar api can be found +# `here `. cmap = mpl.cm.cool norm = mpl.colors.Normalize(vmin=5, vmax=10) @@ -46,24 +46,25 @@ # Discrete intervals colorbar # --------------------------- # -# The second example illustrates the use of a ListedColormap which generates a -# colormap from a set of listed colors, a BoundaryNorm which generates a -# 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. +# The second example illustrates the use of a +# :class:`~matplotlib.colors.ListedColormap` which generates a colormap from a +# set of listed colors, :func:`colors.BoundaryNorm` which generates a 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. # -# If a ListedColormap is used, the length of the bounds array must be -# one greater than the length of the color list. The bounds must be -# monotonically increasing. +# If a :class:`~matplotlib.colors.ListedColormap` is used, the length of the +# bounds array must be one greater than the length of the color list. The +# bounds must be monotonically increasing. # # This time we pass some more arguments in addition to previous arguments to -# ColorBase. For the out-of-range values to display on the colorbar, we have to -# use the extend keyword argument. To use 'extend', you must specify two extra -# boundaries. Finally spacing argument ensures that intervals are shown on -# colorbar proportionally. +# :class:`~matplotlib.colorbar.ColorbarBase`. For the out-of-range values to +# display on the colorbar, we have to use the *extend* keyword argument. To use +# *extend*, you must specify two extra boundaries. Finally spacing argument +# ensures that intervals are shown on colorbar proportionally. -cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c']) +cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan']) cmap.set_over('0.25') cmap.set_under('0.75') @@ -83,16 +84,16 @@ # -------------------------------------- # # 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. +# 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 +# *auto*. -cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], - [1., .8, 0.], [1., .4, 0.]]) -cmap.set_over((1., 0., 0.)) -cmap.set_under((0., 0., 1.)) +cmap = mpl.colors.ListedColormap(['royalblue', 'cyan', + 'yellow', 'orange']) +cmap.set_over('red') +cmap.set_under('blue') -bounds = [-1., -.5, 0., .5, 1.] +bounds = [-1.0, -0.5, 0.0, 0.5, 1.0] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, norm=norm, @@ -105,4 +106,4 @@ cb3.set_label('Custom extension lengths, some other units') plt.tight_layout() -plt.show() +plt.show() \ No newline at end of file From c7f582c5eff1f5ccc5f6c8e8ac0bb98133d48f9b Mon Sep 17 00:00:00 2001 From: patniharshit Date: Fri, 12 May 2017 21:31:46 +0530 Subject: [PATCH 5/9] Change how kwarg extendfrac is presented in colorbar_only tutorial --- tutorials/colors/colorbar_only.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index 739b9535bb1f..a760b48e847c 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -84,9 +84,8 @@ # -------------------------------------- # # Here we illustrate the use of custom length colorbar extensions, used on a -# 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 -# *auto*. +# colorbar with discrete intervals. To make the length of each extension same +# as the length of the interior colors, use extendfrac='auto'. cmap = mpl.colors.ListedColormap(['royalblue', 'cyan', 'yellow', 'orange']) From 00e7d0f95f32dc58d404871bec058ee9c98efa57 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Fri, 12 May 2017 22:27:38 +0530 Subject: [PATCH 6/9] Add double backticks to extendfrac in colorbar_only tutorial --- tutorials/colors/colorbar_only.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index a760b48e847c..114daafcb5b5 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -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'``. cmap = mpl.colors.ListedColormap(['royalblue', 'cyan', 'yellow', 'orange']) From 3c1995424e89b85b8ac5fa90e83608d9ecc6dec5 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Sat, 13 May 2017 10:20:57 +0530 Subject: [PATCH 7/9] Add new line at the end of the file --- tutorials/colors/colorbar_only.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index 114daafcb5b5..849acae928b6 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -105,4 +105,4 @@ cb3.set_label('Custom extension lengths, some other units') plt.tight_layout() -plt.show() \ No newline at end of file +plt.show() From 6ae3c6f77e5bc12b922baecda2c3d1be130d1dc7 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Mon, 15 May 2017 11:12:02 +0530 Subject: [PATCH 8/9] Call for new figure in each rst block --- tutorials/colors/colorbar_only.py | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index 849acae928b6..a9458b52b46d 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -16,31 +16,31 @@ colorbar. We will start by making a figure of desired size and adding three axes. + +Basic continuous colorbar +------------------------- + +Set the colormap and norm to correspond to the data for which the colorbar +will be used. Then create the colorbar by calling +:class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm +and orientation as parameters. Here we create a basic continuous colorbar +with ticks and labels. More information on colorbar api can be found +`here `. """ import matplotlib.pyplot as plt import matplotlib as mpl -fig, (ax1, ax2, ax3) = plt.subplots(nrows=3) - -############################################################################### -# Basic continuous colorbar -# ------------------------- -# -# Set the colormap and norm to correspond to the data for which the colorbar -# will be used. Then create the colorbar by calling -# :class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm -# and orientation as parameters. Here we create a basic continuous colorbar -# with ticks and labels. More information on colorbar api can be found -# `here `. +fig, ax = plt.subplots() cmap = mpl.cm.cool norm = mpl.colors.Normalize(vmin=5, vmax=10) -cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, +cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, orientation='horizontal') cb1.set_label('Some Units') +fig.show() ############################################################################### # Discrete intervals colorbar @@ -64,13 +64,15 @@ # *extend*, you must specify two extra boundaries. Finally spacing argument # ensures that intervals are shown on colorbar proportionally. +fig, ax = plt.subplots() + cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan']) cmap.set_over('0.25') cmap.set_under('0.75') bounds = [1, 2, 4, 7, 8] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) -cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, +cb2 = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, boundaries=[0] + bounds + [13], extend='both', @@ -78,6 +80,7 @@ spacing='proportional', orientation='horizontal') cb2.set_label('Discrete intervals, some other units') +fig.show() ############################################################################### # Colorbar with custom extension lengths @@ -87,6 +90,8 @@ # colorbar with discrete intervals. To make the length of each extension same # as the length of the interior colors, use ``extendfrac='auto'``. +fig, ax = plt.subplots() + cmap = mpl.colors.ListedColormap(['royalblue', 'cyan', 'yellow', 'orange']) cmap.set_over('red') @@ -94,7 +99,7 @@ bounds = [-1.0, -0.5, 0.0, 0.5, 1.0] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) -cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, +cb3 = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, boundaries=[-10] + bounds + [10], extend='both', @@ -103,6 +108,4 @@ spacing='uniform', orientation='horizontal') cb3.set_label('Custom extension lengths, some other units') - -plt.tight_layout() -plt.show() +fig.show() From 2996c49edbc2af7495f97150daeb378281a64c79 Mon Sep 17 00:00:00 2001 From: patniharshit Date: Mon, 15 May 2017 21:21:27 +0530 Subject: [PATCH 9/9] Remove a line asking to create three axes in colorbar_only tutorial --- tutorials/colors/colorbar_only.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tutorials/colors/colorbar_only.py b/tutorials/colors/colorbar_only.py index a9458b52b46d..08616d1cd202 100644 --- a/tutorials/colors/colorbar_only.py +++ b/tutorials/colors/colorbar_only.py @@ -15,8 +15,6 @@ 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 three axes. - Basic continuous colorbar -------------------------