Reputation: 319
I want to plot 2 graphes at one time. 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?
Upvotes: 0
Views: 2214
Reputation: 137438
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"),
]
Upvotes: 2