I just installed plotly express. And I am trying to do something simple - plot each column of my data frame on the same y-axis with the index as x-axis. Here are questions/observations:
Is it necessary for the data frame to have index as a column to be used as x-axis ? Can I not directly use the index for x-axis? How can I add multiple traces as were called in plotly on y-axis for the same x-axis ?
Please note that, I am not trying to add traces using plotly, rather trying to use plotly-express.
Also, there a few similar posts online, the closest was this: https://community.plot.ly/t/multiple-traces-plotly-express/23360 However, this post shows how you can add a scatter, not a line. I want to plot a line and there is no add_line similar to add_scatter shown in the example here.
Appreciate any help in advance
Sample code:
import plotly.express as px
import pandas as pd
import numpy as np
# Get some data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
# Plot
fig = px.line(df, x='Date', y='AAPL.High')
# Only thing I figured is - I could do this
fig.add_scatter(x=df['Date'], y=df['AAPL.Low']) # Not what is desired - need a line
# Show plot
fig.show()
PLot:
df_long=pd.melt(df_wide, id_vars=df_wide.columns[0], value_vars=df_wide.columns[1:])
– Inefficiency