I am running matplotlib and I want to plot a single color, like:
import matplotlib.pyplot as plt
plt.imshow([(100, 100, 200)])
but this is showing a gradient. What is the issue?
This gives only one color:
import matplotlib.pyplot as plt
plt.imshow([[(0, 0, 1)]])

plt.imshow([[(0.5, 0.5, 0.5)]])

You need a shape of MxNx3:
>>> import numpy as np
>>> np.array([[(0.5, 0.5, 0.5)]]).shape
(1, 1, 3)
Here M and N are 1.
plt.imshow(X, ...)
X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4) Display the image in
Xto current axes.Xmay be a float array, a uint8 array or a PIL image. IfXis an array, it can have the following shapes:
- MxN -- luminance (grayscale, float array only)
- MxNx3 -- RGB (float or uint8 array)
MxNx4 -- RGBA (float or uint8 array)
The value for each component of MxNx3 and MxNx4 float arrays should be in the range 0.0 to 1.0; MxN float arrays may be normalized.
You need to convert int to float between 0 and 1:
from __future__ import division # needed for Python 2 only
plt.imshow([[(100 / 255, 100 / 255, 200 / 255)]])

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With