Color Bar Limits

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

Color_Bar.png

Hi John,

I got this off stack exchange, apologies to the original contributor…

Cheers, Jody

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.colors import LinearSegmentedColormap

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=0, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label(‘Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

···

On 2 Apr 2015, at 5:47 AM, John Leeman <kd5wxb@…287…> wrote:

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

<Color_Bar.png>


Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Jody Klymak

http://web.uvic.ca/~jklymak/

No, that’s not what he is asking for. John wants the norm to go from -1 to 4, but he wants the colorbar to display only the 0 to 4 portion. Your approach (setting vmin=0) would change the normalization and change the colors.

The axes limits do not appear to be scaled by the values. They are set to (0, 1). So, the kludgy way would seem to be to set the xlimits to be (0.2, 1) (taking out a fifth of the colorbar, but the frame is still there…

Ben Root

···

On Thu, Apr 2, 2015 at 12:32 PM, Jody Klymak <jklymak@…4192…> wrote:

Hi John,

I got this off stack exchange, apologies to the original contributor…

Cheers, Jody

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.colors import LinearSegmentedColormap

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=0, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label(‘Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

On 2 Apr 2015, at 5:47 AM, John Leeman <kd5wxb@…287…> wrote:

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

<Color_Bar.png>


Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@…1739…ge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody Klymak

http://web.uvic.ca/~jklymak/


Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

No, that’s not what he is asking for. John wants the norm to go from -1 to 4, but he wants the colorbar to display only the 0 to 4 portion. Your approach (setting vmin=0) would change the normalization and change the colors.

Hmm, well his values go from 0 to 4, and he wants his colorbar to go from 0 to 4, but just over the last 4/5ths of the colormap. I think I gave him what he wants. But I guess he can decide!

Cheers, Jody

···

On Thu, Apr 2, 2015 at 12:32 PM, Jody Klymak <jklymak@…4192…> wrote:

Hi John,

I got this off stack exchange, apologies to the original contributor…

Cheers, Jody

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.colors import LinearSegmentedColormap

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=0, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label(‘Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

On 2 Apr 2015, at 5:47 AM, John Leeman <kd5wxb@…287…> wrote:

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

<Color_Bar.png>


Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@…813…ourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody Klymak

http://web.uvic.ca/~jklymak/


Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

::Looks again::

Ok, I see what you did here:

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

I missed this part the first time through, noticing only the change to the vmin. Yeah, I think that would work just fine. Sorry for the confusion.

Cheers!

Ben Root

···

On Thu, Apr 2, 2015 at 12:56 PM, Jody Klymak <jklymak@…4649…> wrote:

On 2 Apr 2015, at 9:50 AM, Benjamin Root <ben.root@…1304…> wrote:

No, that’s not what he is asking for. John wants the norm to go from -1 to 4, but he wants the colorbar to display only the 0 to 4 portion. Your approach (setting vmin=0) would change the normalization and change the colors.

Hmm, well his values go from 0 to 4, and he wants his colorbar to go from 0 to 4, but just over the last 4/5ths of the colormap. I think I gave him what he wants. But I guess he can decide!

Cheers, Jody

The axes limits do not appear to be scaled by the values. They are set to (0, 1). So, the kludgy way would seem to be to set the xlimits to be (0.2, 1) (taking out a fifth of the colorbar, but the frame is still there…

Ben Root

Jody Klymak

http://web.uvic.ca/~jklymak/

On Thu, Apr 2, 2015 at 12:32 PM, Jody Klymak <jklymak@…4192…> wrote:

Hi John,

I got this off stack exchange, apologies to the original contributor…

Cheers, Jody

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.colors import LinearSegmentedColormap

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=0, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label(‘Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

On 2 Apr 2015, at 5:47 AM, John Leeman <kd5wxb@…1003…7…> wrote:

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

<Color_Bar.png>


Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody Klymak

http://web.uvic.ca/~jklymak/


Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody and Ben,

That does the business! I had hunted for awhile, but didn’t find that solution. Thank you for your help!

Cheers,

John Leeman

···

On Thu, Apr 2, 2015 at 12:56 PM, Jody Klymak <jklymak@…4192…> wrote:

On 2 Apr 2015, at 9:50 AM, Benjamin Root <ben.root@…1304…> wrote:

No, that’s not what he is asking for. John wants the norm to go from -1 to 4, but he wants the colorbar to display only the 0 to 4 portion. Your approach (setting vmin=0) would change the normalization and change the colors.

Hmm, well his values go from 0 to 4, and he wants his colorbar to go from 0 to 4, but just over the last 4/5ths of the colormap. I think I gave him what he wants. But I guess he can decide!

Cheers, Jody

The axes limits do not appear to be scaled by the values. They are set to (0, 1). So, the kludgy way would seem to be to set the xlimits to be (0.2, 1) (taking out a fifth of the colorbar, but the frame is still there…

Ben Root

Jody Klymak

http://web.uvic.ca/~jklymak/

On Thu, Apr 2, 2015 at 12:32 PM, Jody Klymak <jklymak@…1686…2…> wrote:

Hi John,

I got this off stack exchange, apologies to the original contributor…

Cheers, Jody

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.colors import LinearSegmentedColormap

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

cmap = plt.get_cmap('rainbow_r’)

start=0.2

stop = 1.

colors = cmap(np.linspace(start, stop, cmap.N))

Create a new colormap from those colors

color_map = LinearSegmentedColormap.from_list(‘Upper Half’, colors)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=0, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label(‘Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

On 2 Apr 2015, at 5:47 AM, John Leeman <kd5wxb@…287…> wrote:

Hi all,

I’m plotting some scatter points colored by a third variable, but want to use a limited subset of a colormap. In the example below, the color axis data ranges from 0-4, but I want to not use the red portion of the bar. Doing the first part is just accomplished by setting the vmin/vmax. But when I plot a color bar I don’t want to show the colors and values for anything below zero. Other than just white-boxing that part of the bar I’m not sure how to do it. I tried a suggestion of setting the limit properties of the bar axis attribute, but that results in the bar getting shrunk and shifted (a very weird behavior). Any ideas?

Thank you,

John Leeman

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(100)

y = np.random.rand(100)

z = 4 * np.random.rand(100)

color_map = plt.get_cmap(‘rainbow_r’)

fig = plt.figure(figsize=(12,9))

ax1 = plt.subplot(111)

sc = ax1.scatter(x, y, c=z, s=50, cmap=color_map, vmin=-1, vmax=4)

position=fig.add_axes([0.37, 0.16, 0.5, 0.02])

cb = fig.colorbar(sc, cax=position, orientation=‘horizontal’, drawedges=False)

cb.set_label('Z-Colors’, fontsize=14)

I tried this after talking with Ben Root, but it

results in some odd behavior

cb.ax.set_xlim(0,4)

plt.show()

<Color_Bar.png>


Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody Klymak

http://web.uvic.ca/~jklymak/


Dive into the World of Parallel Programming The Go Parallel Website, sponsored

by Intel and developed in partnership with Slashdot Media, is your hub for all

things parallel software development, from weekly thought leadership blogs to

news, videos, case studies, tutorials and more. Take a look and join the

conversation now. http://goparallel.sourceforge.net/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users