I am using imshow()
in matplotlib like so:
import numpy as np import matplotlib.pyplot as plt mat = '''SOME MATRIX''' plt.imshow(mat, origin="lower", cmap='gray', interpolation='nearest') plt.show()
How do I add a legend showing the numeric value for the different shades of gray. Sadly, my googling has not uncovered an answer :(
Thank you in advance for the help.
Vince
Simple, just plt.colorbar()
:
import numpy as np import matplotlib.pyplot as plt mat = np.random.random((10,10)) plt.imshow(mat, origin="lower", cmap='gray', interpolation='nearest') plt.colorbar() plt.show()
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