Issue
I have two polygon patch plots with shading in grayscale, with each patch added to an axis. and I would like to add a colorbar underneath each subplot. I'm using
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
poly=mpatches.Polygon(verts,color=rgb,ec='black') #create patch
ax.add_patch(poly) #add patch to axis
plt.set_cmap('gray') #grayscale colormap
#verts,rgb input created in above lines of code
The colorbars should be in grayscale and have range [0,1], with 0 being black, 0.5 marked, and 1 being white. im using subplot(121) and (122). Thanks in advance.
Solution
To use colorbars you have to have some sort of ScalarMappable
instance (this is used for imshow
, scatter
, etc.):
mappable = plt.cm.ScalarMappable(cmap='gray')
# the mappable usually contains an array of data, here we can
# use that to set the limits
mappable.set_array([0,1])
ax.colorbar(mappable)
Answered By - hitzg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.