-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Open
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew featurekeepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actiontopic: mplot3d
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 methods
palette.set_under((0,0,0,0)) #So vmin has an effect
if add_colorbar:
vmax = np.max(NPArr) #NPArr is the data being plotted
norm = 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 Mappable
m.set_array([]) #Makes it the right type so get() methods exist
ticks = 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew featurekeepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actiontopic: mplot3d