添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
`import plotly.plotly as py
 import plotly.graph_objs as go
 from plotly.offline import init_notebook_mode, iplot
 init_notebook_mode()
 trace1 = go.Scatter(x= X,y= Y2 )
 trace2 = go.Bar(x= X,y= Y)
 data = [trace1, trace2]
 fig = py.iplot(data, filename='bar-line')
 plotly.offline.iplot(fig)` 

Thank you

First: you are wrong called fig. Usual fig specified as go.Figure or dict. Second: if you want to get two plots instead of one (you cannot get both in your Figure, because your traces have a different types - one for Scatter, one for Bar) you need to use tools. Third: if you import iplot from plotly.offline, just call it as iplot - here is not needed to call plotly.offline.iplot. Here updated code a little bit:

from plotly import tools
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
trace1 = go.Scatter(x=X, y=Y2)
trace2 = go.Bar(x=X, y=Y)
data = [trace1, trace2]
fig = tools.make_subplots(rows=1, cols=2)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)
iplot(fig)

Also I suggested you take a look about subplots - how to plot few plots at one page. And stacked bar chart - maybe your goal is to get a plot as described here. Hope it helps

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.