Pyplot plot image with colormap and sequence of alpha2019 Community Moderator ElectionHow to put the legend out of the plotSave plot to image file instead of displaying it using MatplotlibCreate a gray scale colormap with colorbar on PythonHow to generate random colors in matplotlib?How to make IPython notebook matplotlib plot inlineLogarithmic colormap in matplotlibPlotting an irregularly-spaced RGB image in Pythonuse matplotlib color map for color cycleSelecting a single color from a matplotlib colormap in JuilaHow to avoid automatic pseudo coloring in matplotlib.pyplot imshow()
Latest web browser compatible with Windows 98
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
Is going from continuous data to categorical always wrong?
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
What is the dot in “1.2.4."
If the Captain's screens are out, does he switch seats with the co-pilot?
Good allowance savings plan?
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
"One can do his homework in the library"
Straight line with arrows and dots
Why does the negative sign arise in this thermodynamic relation?
Constexpr variable captured inside lambda loses its constexpr-ness
Can someone explain what is being said here in color publishing in the American Mathematical Monthly?
Missing Sitecore Toolbar in Content tree
How does airport security verify that you can carry a battery bank over 100 Wh?
Etymology of ambulance
What's the italian equivalent for "hiring managers"?
Virginia employer terminated employee and wants signing bonus returned
Does a Catoblepas statblock appear in an official D&D 5e product?
Is "history" a male-biased word ("his+story")?
Does splitting a potentially monolithic application into several smaller ones help prevent bugs?
Using for loop in tikz to draw repeated shapes
Should QA ask requirements to developers?
What features to consider when selecting a ring flash?
Pyplot plot image with colormap and sequence of alpha
2019 Community Moderator ElectionHow to put the legend out of the plotSave plot to image file instead of displaying it using MatplotlibCreate a gray scale colormap with colorbar on PythonHow to generate random colors in matplotlib?How to make IPython notebook matplotlib plot inlineLogarithmic colormap in matplotlibPlotting an irregularly-spaced RGB image in Pythonuse matplotlib color map for color cycleSelecting a single color from a matplotlib colormap in JuilaHow to avoid automatic pseudo coloring in matplotlib.pyplot imshow()
With the imshow function from pyplot, I can plot an (M,N) size image, where each value in the (M,N) sized array is associated to a color from a colormap
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
plt.imshow(A, cmap='jet')
plt.colorbar()
plt.show()
I have an (2,M,N) sized array (let's call it B) that I would like to show. B[0] gives the hue and B[1] is the alpha. Here, B[0] would be the same as A in the first example.
I would like to write something like plt.imshow(B[0], cmap='jet', alpha=B[1]). But the value of the alpha has to be the same for the entire image, since the alpha option has to be a scalar or None
With imshow, I can also specify an (M,N,3) or an (M,N,4) array, where the value for R,G,B and alpha are given. However, I don't know how to get the RGB values from my initial (M,N) sized array A.
I tried setting the color with the HSV scheme from my values, then converting to RGB and plotting with those colors
from matplotlib import colors
B = np.random.rand(2,5,5)
hue = B[0]
sat = B[1]
val = np.ones(B[0].shape)
rgb = colors.hsv_to_rgb(np.array([hue, sat, val]).T)
plt.imshow(rgb)
plt.show()
But then, I don't know how to make a color bar from the actual values in B.
I'm going for something like this:
where the vertical part of the colorbar shows the value in B[0] and the horizontal part of the colorbar shows the value in B[1].
python matplotlib colors
add a comment |
With the imshow function from pyplot, I can plot an (M,N) size image, where each value in the (M,N) sized array is associated to a color from a colormap
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
plt.imshow(A, cmap='jet')
plt.colorbar()
plt.show()
I have an (2,M,N) sized array (let's call it B) that I would like to show. B[0] gives the hue and B[1] is the alpha. Here, B[0] would be the same as A in the first example.
I would like to write something like plt.imshow(B[0], cmap='jet', alpha=B[1]). But the value of the alpha has to be the same for the entire image, since the alpha option has to be a scalar or None
With imshow, I can also specify an (M,N,3) or an (M,N,4) array, where the value for R,G,B and alpha are given. However, I don't know how to get the RGB values from my initial (M,N) sized array A.
I tried setting the color with the HSV scheme from my values, then converting to RGB and plotting with those colors
from matplotlib import colors
B = np.random.rand(2,5,5)
hue = B[0]
sat = B[1]
val = np.ones(B[0].shape)
rgb = colors.hsv_to_rgb(np.array([hue, sat, val]).T)
plt.imshow(rgb)
plt.show()
But then, I don't know how to make a color bar from the actual values in B.
I'm going for something like this:
where the vertical part of the colorbar shows the value in B[0] and the horizontal part of the colorbar shows the value in B[1].
python matplotlib colors
add a comment |
With the imshow function from pyplot, I can plot an (M,N) size image, where each value in the (M,N) sized array is associated to a color from a colormap
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
plt.imshow(A, cmap='jet')
plt.colorbar()
plt.show()
I have an (2,M,N) sized array (let's call it B) that I would like to show. B[0] gives the hue and B[1] is the alpha. Here, B[0] would be the same as A in the first example.
I would like to write something like plt.imshow(B[0], cmap='jet', alpha=B[1]). But the value of the alpha has to be the same for the entire image, since the alpha option has to be a scalar or None
With imshow, I can also specify an (M,N,3) or an (M,N,4) array, where the value for R,G,B and alpha are given. However, I don't know how to get the RGB values from my initial (M,N) sized array A.
I tried setting the color with the HSV scheme from my values, then converting to RGB and plotting with those colors
from matplotlib import colors
B = np.random.rand(2,5,5)
hue = B[0]
sat = B[1]
val = np.ones(B[0].shape)
rgb = colors.hsv_to_rgb(np.array([hue, sat, val]).T)
plt.imshow(rgb)
plt.show()
But then, I don't know how to make a color bar from the actual values in B.
I'm going for something like this:
where the vertical part of the colorbar shows the value in B[0] and the horizontal part of the colorbar shows the value in B[1].
python matplotlib colors
With the imshow function from pyplot, I can plot an (M,N) size image, where each value in the (M,N) sized array is associated to a color from a colormap
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
plt.imshow(A, cmap='jet')
plt.colorbar()
plt.show()
I have an (2,M,N) sized array (let's call it B) that I would like to show. B[0] gives the hue and B[1] is the alpha. Here, B[0] would be the same as A in the first example.
I would like to write something like plt.imshow(B[0], cmap='jet', alpha=B[1]). But the value of the alpha has to be the same for the entire image, since the alpha option has to be a scalar or None
With imshow, I can also specify an (M,N,3) or an (M,N,4) array, where the value for R,G,B and alpha are given. However, I don't know how to get the RGB values from my initial (M,N) sized array A.
I tried setting the color with the HSV scheme from my values, then converting to RGB and plotting with those colors
from matplotlib import colors
B = np.random.rand(2,5,5)
hue = B[0]
sat = B[1]
val = np.ones(B[0].shape)
rgb = colors.hsv_to_rgb(np.array([hue, sat, val]).T)
plt.imshow(rgb)
plt.show()
But then, I don't know how to make a color bar from the actual values in B.
I'm going for something like this:
where the vertical part of the colorbar shows the value in B[0] and the horizontal part of the colorbar shows the value in B[1].
python matplotlib colors
python matplotlib colors
asked Mar 6 at 16:36
usernumberusernumber
308318
308318
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The first part is relatively straight forward:
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
cmap = plt.get_cmap('jet')
rgba_img = cmap(A)
rgba_img[:, :, 3] = np.random.rand(5, 5)
plt.imshow(rgba_img)
plt.colorbar()
plt.show()
Making a colorbar is more difficult. You will basically need to replace the pcolor that is used to make the colorbar with another one that looks as you want it to.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028005%2fpyplot-plot-image-with-colormap-and-sequence-of-alpha%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The first part is relatively straight forward:
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
cmap = plt.get_cmap('jet')
rgba_img = cmap(A)
rgba_img[:, :, 3] = np.random.rand(5, 5)
plt.imshow(rgba_img)
plt.colorbar()
plt.show()
Making a colorbar is more difficult. You will basically need to replace the pcolor that is used to make the colorbar with another one that looks as you want it to.
add a comment |
The first part is relatively straight forward:
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
cmap = plt.get_cmap('jet')
rgba_img = cmap(A)
rgba_img[:, :, 3] = np.random.rand(5, 5)
plt.imshow(rgba_img)
plt.colorbar()
plt.show()
Making a colorbar is more difficult. You will basically need to replace the pcolor that is used to make the colorbar with another one that looks as you want it to.
add a comment |
The first part is relatively straight forward:
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
cmap = plt.get_cmap('jet')
rgba_img = cmap(A)
rgba_img[:, :, 3] = np.random.rand(5, 5)
plt.imshow(rgba_img)
plt.colorbar()
plt.show()
Making a colorbar is more difficult. You will basically need to replace the pcolor that is used to make the colorbar with another one that looks as you want it to.
The first part is relatively straight forward:
import numpy as np
import matplotlib.pyplot as plt
A = np.random.rand(5,5)
cmap = plt.get_cmap('jet')
rgba_img = cmap(A)
rgba_img[:, :, 3] = np.random.rand(5, 5)
plt.imshow(rgba_img)
plt.colorbar()
plt.show()
Making a colorbar is more difficult. You will basically need to replace the pcolor that is used to make the colorbar with another one that looks as you want it to.
answered Mar 6 at 18:51
Jody KlymakJody Klymak
1947
1947
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028005%2fpyplot-plot-image-with-colormap-and-sequence-of-alpha%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown