Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Doc]: add histogram as colorbar example #30026

Open
@story645

Description

@story645

Documentation Link

No response

Problem

Making a colorbar histogram is a kinda popular visualization that's not difficult but I figure finnicky enough that it's worth adding an example to the gallery.

Suggested improvement

I've got one here to explain what I mean but I'm making this an issue so that maybe someone who has a better example can have fun with this:

Image

x=np.random.random(100).reshape(10,10)counts,bins=np.histogram(x)cmap=plt.colormaps['viridis']norm=mcolors.BoundaryNorm(bins,cmap.N)fig,ax=plt.subplots()im=ax.imshow(x,cmap=cmap,norm=norm)cbar=plt.colorbar(im)cax=ax.inset_axes([1.5,0,.25,1])midpoints=bins[:-1]+np.diff(bins)/2cax.barh(midpoints,counts,height=1/len(counts),color=cmap(norm(midpoints)))cax.set_yticks(bins)cax.margins(0)cax.spines[:].set_visible(False)

I'm making cax an inset_axes here mostly because a lot of the real use cases for this are maps where it's nice to have a lot of control on where to put the histogram. I figure this example should live in color. Would be even nicer with#26312 and colorizer 'cause then I think the syncing is managed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp