2016-07-27 29 views
2

Ich habe drei Spuren, von denen eine in einem Teilplot und zwei in einem anderen sind. Ich hätte gerne eine eigene Y-Achse für jede Spur im Teilplot mit 2 Spuren.Wie füge ich eine Achse für eine zweite Kurve in einem Plotly-Unterplot hinzu?

Zum Beispiel, ich habe

fig = plotly.tools.make_subplots(rows=2, cols=1, shared_xaxes=True) 
fig.append_trace(trace1, 1, 1) 
fig.append_trace(trace2, 1, 1) 
fig.append_trace(trace3, 2, 1) 
fig['layout'].update(height=200, width=400) 

die

enter image description here

produziert Und wenn ich keine Nebenhandlungen habe, kann ich eine zweite Achse für die zweite Spur erhalten mit

layout = go.Layout(
    yaxis=dict(
     title='y for trace1' 
    ), 
    yaxis2=dict(
     title='y for trace2', 
     titlefont=dict(
      color='rgb(148, 103, 189)' 
     ), 
     tickfont=dict(
      color='rgb(148, 103, 189)' 
     ), 
     overlaying='y', 
     side='right' 
    ) 
) 
fig = go.Figure(data=data, layout=layout) 

, die

produziert

enter image description here

Aber ich kann nicht herausfinden, wie die erste Teilfläche im ersten Beispiel wie die Handlung im zweiten Beispiel zu sehen bekommen: mit einer deutlichen Achse für die zweite Spur gibt.

Wie füge ich eine Achse für eine zweite Kurve in einem Plotly-Unterplot hinzu?

Antwort

0

Dies ist ein bisschen ein Problem zu umgehen, aber es scheint zu funktionieren:

import plotly as py 
import plotly.graph_objs as go 
from plotly import tools 
import numpy as np 

left_trace = go.Scatter(x = np.random.randn(1000), y = np.random.randn(1000), yaxis = "y1", mode = "markers") 
right_traces = [] 
right_traces.append(go.Scatter(x = np.random.randn(1000), y = np.random.randn(1000), yaxis = "y2", mode = "markers")) 
right_traces.append(go.Scatter(x = np.random.randn(1000) * 10, y = np.random.randn(1000) * 10, yaxis = "y3", mode = "markers")) 

fig = tools.make_subplots(rows = 1, cols = 2) 
fig.append_trace(left_trace, 1, 1) 
for trace in right_traces: 
    yaxis = trace["yaxis"] # Store the yaxis 
    fig.append_trace(trace, 1, 2) 
    fig["data"][-1].update(yaxis = yaxis) # Update the appended trace with the yaxis 

fig["layout"]["yaxis1"].update(range = [0, 3], anchor = "x1", side = "left") 
fig["layout"]["yaxis2"].update(range = [0, 3], anchor = "x2", side = "left") 
fig["layout"]["yaxis3"].update(range = [0, 30], anchor = "x2", side = "right", overlaying = "y2") 

py.offline.plot(fig) 

Produziert dies, wo trace0 im ersten subplot auf yaxis1 aufgetragen ist, und trace1 und trace2 in der zweiten subplot ist, aufgetragen auf yaxis2 (0-3) und yaxis3 (0-30), das jeweils: enter image description here

Wenn Spuren zu Nebenhandlungen angehängt werden, die x-Achse und y-Achse überschrieben zu werden scheinen, oder das ist meine verstehen ing von this discussion sowieso.