Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Problem
Hi;
I'm working with 3D plots and I use colored voxels to plots a 4th dimension.
When one wants to use a colorbar, one usually uses an image or a contourf in the colorbar creation method like so :
img = ax.imshow(event, **cmap_args)plt.colorbar(img)
It is very handful to handle all the colormap arguments (such as vmin etc) directly from the image but doesn't work with voxels.
Currently I use this :
`
palette=mpl.cm.get_cmap("viridis",lut=levels).copy() #simulate the level arg of other plot methodspalette.set_under((0,0,0,0)) #So vmin has an effectif add_colorbar:vmax = np.max(NPArr) #NPArr is the data being plottednorm = mpl.colors.Normalize(0,vmax) #Necessary because there is no mappable from voxels, instead of normalizing the data it is easier to normalize the "cmap"m = cm.ScalarMappable(cmap=palette,norm=norm) #Creates Mappablem.set_array([]) #Makes it the right type so get() methods existticks = np.linspace(1,vmax,levels+1)fig.colorbar(m, ax=ax, extend="min", ticks=ticks) #Finally creates the cmap with other cmap arguments that can't be passed to the mappable
`
Voxels give dictionnary of 3d objet so I have tried to use one of its value as mappable which works but doesn't bring all the data info for the colormap.
Proposed solution
No response