情节覆盖没有痕迹的传奇名称
我正在尝试更改传奇名称,但我找到了许多答案,但是如果您不使用痕迹,则它们都没有起作用。我学会了更改传奇标题,但没有更改名称。 这是我的代码,希望有人可以提供帮助:
import pandas as pd
import plotly.express as px
import numpy as np
def camasRegion():
df = pd.read_csv('https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/master/output/producto52/Camas_UCI.csv')
dates = df.columns #for some reason I can't use this as x axis
habilitadas = []
ocupadasCovid = []
ocupadasNoCovid = []
region = 'Ñuble'
for i in range(len(df)):
if df.values[i][0] == region:
if df.values[i][1] == 'Camas UCI habilitadas':
for x in range(len(df.columns)):
habilitadas.append(df.values[i][x])
if df.values[i][1] == 'Camas UCI ocupadas COVID-19':
for x in range(len(df.columns)):
ocupadasCovid.append(df.values[i][x])
if df.values[i][1] == 'Camas UCI ocupadas no COVID-19':
for x in range(len(df.columns)):
ocupadasNoCovid.append(df.values[i][x])
fig = px.line(df,
y = [habilitadas, ocupadasCovid, ocupadasNoCovid],
x = range(len(fechas)), #I'm doing this because x = dates doesn't work
title='Camas por región: ('+region+')',)
fig.add_annotation(
x = 1, y = -0.1,
text = 'Fuente: Datos obtenidos desde el Ministerio de Ciencia.',
showarrow = False, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=-20
)
fig.update_layout(
legend_title_text='Estado de cama',
xaxis_title="Días",
yaxis_title="Cantidad de camas",
)
fig.show()
camasRegion()
I'm trying to change the legend names and I've found many answers but none of them works if you are not using traces. I learned to change the legend title but not the names.
Here it is my code, hopefully somebody can help:
import pandas as pd
import plotly.express as px
import numpy as np
def camasRegion():
df = pd.read_csv('https://raw.githubusercontent.com/MinCiencia/Datos-COVID19/master/output/producto52/Camas_UCI.csv')
dates = df.columns #for some reason I can't use this as x axis
habilitadas = []
ocupadasCovid = []
ocupadasNoCovid = []
region = 'Ñuble'
for i in range(len(df)):
if df.values[i][0] == region:
if df.values[i][1] == 'Camas UCI habilitadas':
for x in range(len(df.columns)):
habilitadas.append(df.values[i][x])
if df.values[i][1] == 'Camas UCI ocupadas COVID-19':
for x in range(len(df.columns)):
ocupadasCovid.append(df.values[i][x])
if df.values[i][1] == 'Camas UCI ocupadas no COVID-19':
for x in range(len(df.columns)):
ocupadasNoCovid.append(df.values[i][x])
fig = px.line(df,
y = [habilitadas, ocupadasCovid, ocupadasNoCovid],
x = range(len(fechas)), #I'm doing this because x = dates doesn't work
title='Camas por región: ('+region+')',)
fig.add_annotation(
x = 1, y = -0.1,
text = 'Fuente: Datos obtenidos desde el Ministerio de Ciencia.',
showarrow = False, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=-20
)
fig.update_layout(
legend_title_text='Estado de cama',
xaxis_title="Días",
yaxis_title="Cantidad de camas",
)
fig.show()
camasRegion()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用日期,因为除了日期外,df.columns包含
region
和serie
。我简化了您的代码,这也使其更具可读性。尝试一下,让我知道,如果它仍然对您不起作用。结果:

You can't use dates, because df.columns besides dates contains strings
Region
andSerie
. I simplified your code, it also made it more readable. Try this and let me know, if it still not working for you.The result:
