2016-07-27 2 views
2

J'ai trois traces, dont une dans une sous-placette, et deux dans une autre. Je voudrais avoir un axe Y distinct de chacune des traces dans la sous-parcelle avec 2 traces.Comment ajouter un axe pour une deuxième trace dans une sous-placette Plotly?

Par exemple, je

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) 

qui produit

enter image description here

Et quand je n'ai pas sous-parcelles, je peux obtenir un second axe pour la deuxième trace avec

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) 

qui produit

enter image description here

Mais je ne peux pas comprendre comment obtenir la première intrigue secondaire dans le premier exemple pour ressembler à l'intrigue dans le second exemple: avec un axe distinct pour la deuxième trace là.

Comment puis-je ajouter un axe pour une seconde trace dans une intrigue secondaire Plotly?

Répondre

0

C'est un peu d'une solution de contournement, mais il semble fonctionner:

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) 

génère ce, où trace0 est dans la première intrigue secondaire tracée sur yaxis1 et trace1 et trace2 sont dans la deuxième intrigue secondaire, tracé sur yaxis2 (0-3) et yaxis3 (0-30) respectivement: enter image description here

Lorsque des traces sont ajoutées à des intrigues secondaires, et les xaxis Yaxis semblent être réécrits ou c'est mon comprendre de this discussion de toute façon.