Hi! I’m trying to build an app that plot the API Response fron the Bank of México. This responses are in json format like this:
[
{
"idSerie": "SF282",
"titulo": "Cetes 28 días Tasa de rendimiento promedio mensual, en por ciento anual",
"datos": [
{
"fecha": "01/01/2019",
"dato": "7.95"
},
{
"fecha": "01/02/2019",
"dato": "7.93"
}
]
},
{
"idSerie": "SP30577",
"titulo": "Índice Nacional de Precios al consumidor Variación mensual",
"datos": [
{
"fecha": "01/01/2019",
"dato": "0.09000000"
},
{
"fecha": "01/02/2019",
"dato": "-0.03000000"
}
]
}
]
I have a function that extrat the data to build a pandas dataframe. As you can see in the json response there are two series to trace in a px.line() plot. At the beginning it was just on big line all over the plot, but after making y=[df[“y0”], df[“y1”]] it suddenly work with the two traces on same plot. I would like to know why it works? i have already search in the documentation and could’t find something :c
i leave the code that makes the plot with the api response from de central bank of mexico. Also i would like to know how are in the documentation plots like this one with no special configuration like mine and just one pandas dataframe.
Thank you and Greetings from Mexico
dates = [[], []]
data = [[], []]
for dictionary in content_json:
for values in dictionary['datos']:
if dictionary["idSerie"] == "SF282":
dates[0].append(values["fecha"])
data[0].append(float(values["dato"]))
else:
dates[1].append(values["fecha"])
data[1].append(float(values["dato"]))
df = pd.DataFrame({
"x0": dates[0],
"y0": data[0],
"x1": dates[1],
"y1": data[1],
})
fig = px.line(df, x='x0', y=[df["y0"],df["y1"]], title="MX Market")
fig.write_html('tmp.html', auto_open=True)