简体   繁体   English

为什么使用 plotly 制作 plot 时,我收到此代码的无效语法错误?

[英]Why am I receiving an invalid syntax error for this code to make a plot using plotly?

I have two data frames (gyeEUR and gyeEMR) wit incident cases per 100k measured in different countries by year.我有两个数据框(gyeEUR 和 gyeEMR),每年在不同国家/地区测量每 10 万例事件。 I am looking to make 2 side by side scatter plots in plotly with year on the x axis and incident cases per 100k on the y axis and different colored lines for the different countries.我希望在 plotly 中制作 2 个并排散点图,x 轴为年份,y 轴为每 100k 的事件案例,不同国家/地区的不同颜色线。 I am using the following code:我正在使用以下代码:

fig = make_subplots(rows=2, cols=1)

fig.add_trace(
    go.Scatter(x=gyeEMR["year"], y=gyeEMR["incident cases per 100k", color=gyeEMR["country"]], row=1, col=1
)
fig.add_trace(
    go.Scatter(x=gyeEUR["year"], y=gyeEUR["incident cases per 100k"], color=gyeEUR["country"]),
    row=2, col=1
)

fig.update_layout(height=600, width=800)
fig.show()

This code has been returning an invalid syntax error for fig.add_trace and I don't understand why.此代码一直为 fig.add_trace 返回无效的语法错误,我不明白为什么。 Could someone point me towards what I am doing wrong?有人可以指出我做错了什么吗?

Edit: Here is the error编辑:这是错误

在此处输入图像描述

Edit: Here is the gyeEMR dataframe编辑:这里是 gyeEMR dataframe

在此处输入图像描述

You one missing one paranthesis in the first add_trace :您在第一个add_trace中缺少一个括号:

fig.add_trace(
    go.Scatter(x=gyeEMR["year"], y=gyeEMR["incident cases per 100k"], color=gyeEMR["country"], row=1, col=1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我无法使用 px.scatter 图绘制包含子图的图? - Why am I unable to make a plot containing subplots in plotly using a px.scatter plot? 为什么我的语法错误无效? - Why am I getting an invalid syntax error? 为什么我会收到这个无效的语法错误? - Why am I getting this invalid syntax error? 我收到代码中未包含的字符的语法错误 - I am receiving a syntax error for a character not in my code 我写了一段代码,但在编辑器中使用 matplotlib 时出现错误我收到无效语法错误,有人知道为什么吗? - I've write a code and I'm getting error while using matplotlib in the editor I am getting invalid syntax error, does anyone know why? 为什么我在使用 pylab 制作条形图时收到此错误 - Why am I receiving this error when using pylab to make a bar graph 为什么会收到有关使用Elif语句的SyntaxError:无效语法? - Why am I receiving a SyntaxError: invalid syntax regarding the use of an elif statement? 为什么我在 elif 行中收到无效的语法错误? - Why am I getting an Invalid Syntax Error in the elif line? 为什么我收到无效的语法 easy_install 错误? - Why am I getting an invalid syntax easy_install error? 为什么在出现 IF 条件后会出现“无效语法”错误? - Why am I getting an 'Invalid syntax' error after an IF condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM