I have a 2x2x3 numpy array like this
<code>import matplotlib.pyplot as plt
import numpy as np
red = np.array([[0, 50], [100, 200]])
green = np.array([[0, 185], [100, 255]])
blue = np.array([[0, 129], [0, 255]])
combined = np.stack((red, green, blue), -1)
# [[[ 0, 0, 0],
# [ 50, 185, 129]],
# [[100, 100, 0],
# [200, 255, 255]]]
</code>
<code>import matplotlib.pyplot as plt
import numpy as np
red = np.array([[0, 50], [100, 200]])
green = np.array([[0, 185], [100, 255]])
blue = np.array([[0, 129], [0, 255]])
combined = np.stack((red, green, blue), -1)
# [[[ 0, 0, 0],
# [ 50, 185, 129]],
# [[100, 100, 0],
# [200, 255, 255]]]
</code>
import matplotlib.pyplot as plt
import numpy as np
red = np.array([[0, 50], [100, 200]])
green = np.array([[0, 185], [100, 255]])
blue = np.array([[0, 129], [0, 255]])
combined = np.stack((red, green, blue), -1)
# [[[ 0, 0, 0],
# [ 50, 185, 129]],
# [[100, 100, 0],
# [200, 255, 255]]]
I can plot the array with color just fine.
<code>plt.figure()
im = plt.imshow(
X=combined,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
</code>
<code>plt.figure()
im = plt.imshow(
X=combined,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
</code>
plt.figure()
im = plt.imshow(
X=combined,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
I can also plot just the red channel, like this
<code>reds = combined.copy()
reds[:, :, 1:] = 0
plt.figure()
im = plt.imshow(
X=reds,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
</code>
<code>reds = combined.copy()
reds[:, :, 1:] = 0
plt.figure()
im = plt.imshow(
X=reds,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
</code>
reds = combined.copy()
reds[:, :, 1:] = 0
plt.figure()
im = plt.imshow(
X=reds,
vmin=0,
vmax=255,
interpolation='none',
aspect='equal',
)
plt.colorbar()
plt.show()
But I’m struggling with two questions..
- Is the colorbar in the first plot event valid. I’m not sure how to interpret it.
- How do change the colorbar in the second plot to go from 0 (black) to 255 (red), as it should? Obviously I want the colorbar values and scale to match the actual plot behavior.