Non-standard routines for matplotlib which can be useful at times.
matplotlib-routines's Introduction
Matplotlib Routines
1. How to Set Custom Colorbar
importmatplotlibasmpl# Get colormap of range [0,1]color_map=mpl.cm.get_cmap('Blues')
# Set normalizer to your data rangenorm=mpl.colors.Normalize(vmin=10, vmax=200)
# Function to get color based on scalar valuesget_color=lambdax : color_map(norm(x))
# Get color corresponding to valueget_color(200)
# Set scalar mappable, to allow plotting of colorbarscalar_map=mpl.cm.ScalarMappable(norm=norm, cmap=color_map)
# Plot colorbar onto figureplt.colorbar(scalar_map, label='Colorbar Title')
x=np.random.rand(100)
y=np.random.rand(100)
s=np.random.randint(10,250,100)
sc=plt.scatter(x,y,s,color='white',edgecolor='black')
# can be sizes or colors# num can be int or listhandle, label=sc.legend_elements('sizes', num=[200,150,100,50], color='white',
mec='black')
plt.legend(handle, label)