[英]SyntaxError: invalid syntax Why does such an error happen?
I want to plot 2 graphes at one time. 我想一次绘制2个图形。 I wrote codes in Jupiter notebook like 我在木星笔记本上写了代码
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly
import plotly.graph_objs as go
import plotly.offline as offline
plotly.offline.init_notebook_mode(connected=False)
x = "test.csv"
df = pd.read_csv(x)
a = df["A"].values.tolist()
b = df["B"].values.tolist()
a = pd.Series(a)
b = pd.Series(b)
data = [
plotly.graph_objs.Scatter(y = a, mode = 'lines', name = 'A')
plotly.graph_objs.Scatter(y = b, mode = 'lines', name = 'B', yaxis="y2")
]
layout = plotly.graph_objs.Layout(
title="A&B",
xaxis={"title":"Date"},
yaxis={"title":"Data-a"},
yaxis2={"title":"Data-b", "overlaying":"y", "side":"right"},
)
fig = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
When I run it, I get this error: 运行它时,出现以下错误:
plotly.graph_objs.Scatter(y = b, mode = 'lines', name = ‘B’, yaxis="y2")
^
SyntaxError: invalid syntax
I think no syntax error in the codes, so I really cannot understand why such an error happens. 我认为代码中没有语法错误,因此我真的无法理解为什么会发生这种错误。 What is wrong in my codes?How should I fix this? 我的代码有什么问题我该如何解决?
You're missing commas at the end of these lines: 这些行的末尾缺少逗号:
data = [
plotly.graph_objs.Scatter(y = a, mode = 'lines', name = 'A'),
plotly.graph_objs.Scatter(y = b, mode = 'lines', name = 'B', yaxis="y2"),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.