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

[ENH]: See through SpanSelector #24038

Open
@ianhi

Description

@ianhi

Problem

I would like a SpanSelector that obscures everywhere but the area selected. This is nice for things like selecting a region of a histogram to threshold an image.

Example of what I want:

Code for below
importmatplotlib.pyplotaspltfrommatplotlib.patchesimportRectanglefrommatplotlib.widgetsimportSpanSelectorimportnumpyasnpdefsee_through_span_selector(ax,onselect=None,init_extents=None):"""    A spanselector that is see through in the selected range.    Parameters    ----------    ax : matplotlib.axes.Axis    onselect : callback    init_extents : (float, float)        If *None* then use the 25% and 75% of xlim    """fig=ax.get_figure()props=dict(alpha=.5,facecolor="k")trans=ax.get_xaxis_transform()w,h=0,1left_rect=Rectangle((0,0),w,h,transform=trans,visible=True,**props)ax.add_patch(left_rect)right_rect=Rectangle((0,0),w,h,transform=trans,visible=True,**props)ax.add_patch(right_rect)defonmove(xmin,xmax):xlims=ax.get_xlim()left_rect.set_width(xmin-min(xlims))left_rect.set_x(min(xlims))right_rect.set_x(xmax)right_rect.set_width(max(xlims)-xmax)onselect(xmin,xmax)fig.canvas.draw_idle()defnull(*args,**kwargs):passspan=SpanSelector(ax,null,"horizontal",props=dict(alpha=0,facecolor="k"),interactive=True,drag_from_anywhere=True,onmove_callback=onmove,useblit=True    )ifinit_extentsisNone:init_extents= (xlims[0]*.25,xlims[1]*.75)span.extents=init_extentsonmove(*span.extents)returnspannp.random.seed(19680801)N=128img=np.random.randn(N,N)fig,axs=plt.subplots(1,2,figsize=(10,5))im=axs[0].imshow(img)axs[1].hist(img.flatten(),bins='auto')defupdate(vmin,vmax):im.norm.vmin=vminim.norm.vmax=vmaxspan=see_through_span_selector(axs[1],update,init_extents= (-2,2))

Peek 2022-09-28 17-18

Proposed solution

Add an option to spanselector that effectively does the above.

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