Plotly의 사용자 정의 버튼을 사용하여 패싯 플롯에서`shared_yaxes`를 업데이트 할 수 있습니까?

엘리 크스

나는 줄거리를 사용하고 있으며 하위 그림이있는 그림이 있습니다. 속성을 토글하는 버튼을 포함하고 싶습니다 shared_yaxes. 이것이 가능한가?

여기에 재현 가능한 예제가 있습니다 (python). 공식적인 단순 서브 플롯 예제를 고려하십시오 .

from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)

이것은 다음을 생성합니다. 여기에 이미지 설명 입력

이제의 shared_yaxes인수를 사용하여 make_subplots두 플롯에 동일한 y 스케일을 적용 할 수 있습니다.

from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2, shared_yaxes=True)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)

그리고 다음을 얻습니다.

여기에 이미지 설명 입력

이제 해당 속성을 토글하기 위해 사용자 지정 컨트롤 (이상적으로는 확인란)을 포함하고 싶습니다 (R 및 Shiny를 사용하여이 작업을 수행했지만 이제는이 플롯 기반 솔루션을 원합니다).

나는 함께 해봤 사용자 정의 버튼 아래에이 코드를 사용하여 예를 들어,하지만 난 그것을 작동 할 수 없습니다.

fig.update_layout(updatemenus=[
    go.layout.Updatemenu(type="buttons",
                         direction="left",
                         buttons=list([
                             dict(args=[{
                                 "shared_yaxes": True
                             }],
                                  label="Shared axes",
                                  method="relayout"),
                             dict(args=[{
                                 "shared_yaxes": False
                             }],
                                  label="Independent axes",
                                  method="relayout")
                         ]),
                         xanchor="left",
                         yanchor="top"),
])

여기에 이미지 설명 입력

그것을 작동시키는 방법에 대한 모든 아이디어를 많이 주시면 감사하겠습니다.

Vestland

아래 설정에서 'matches': 'y''matches': Nonefor 사이를 전환하여 수행 할 수 있습니다 'yaxis2'.

출력 1 :

여기에 이미지 설명 입력

출력 2 :

여기에 이미지 설명 입력

암호:

# imports
from plotly.subplots import make_subplots
import plotly.graph_objects as go

# plotly basic setup
fig = make_subplots(rows=1, cols=2, shared_yaxes=True)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)

# plotly figure updates
fig.update_layout(
    updatemenus=[
        go.layout.Updatemenu(buttons=list([
            dict(label='Shared',
                 method='relayout',
                 args=['yaxis2', {'anchor': 'x2', 'domain': [0.0, 1.0],
                                  'matches': 'y', 'showticklabels': False}]),
            dict(label='Not shared',
                 method='relayout',
                 args=['yaxis2', {'anchor': 'x2', 'domain': [0.0, 1.0],
                                  'matches': None, 'showticklabels': True}]),
        ]),
        )
    ]
)

fig.show()

편집 : 버튼 기본 설정과 일치해야하는 설정은 다음과 같습니다.

여기에 이미지 설명 입력

암호:

# imports
from plotly.subplots import make_subplots
import plotly.graph_objects as go

# plotly basic setup
fig = make_subplots(rows=1, cols=2, shared_yaxes=True)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)

# plotly figure updates
fig.update_layout(
    updatemenus=[
        go.layout.Updatemenu(type='buttons',
                             direction='left',
                             xanchor='left',
                             yanchor='top',
                             buttons=list([
                                    dict(label='Shared axes',
                                         method='relayout',
                                         args=['yaxis2', {'anchor': 'x2', 'domain': [0.0, 1.0],
                                                          'matches': 'y', 'showticklabels': False}]),
                                    dict(label='Independent axes',
                                         method='relayout',
                                         args=['yaxis2', {'anchor': 'x2', 'domain': [0.0, 1.0],
                                                          'matches': None, 'showticklabels': True}]),
                                            ]),
        )
    ]
)

fig.show()

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관