'Plotting information from certain Excel spreadsheet
I have an Excel file with various spreadsheets and I want to create a graph from a certain spreadsheet (Details) with plotly.
I use the following code, but the f = Path.cwd().joinpath('MyFile.xlsm') seems to be an issue because I use this command wrong...but actually I dont know how to use it correctly.
Thanks.
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import openpyxl as xl
from pathlib import Path
# Get some data
df1 = pd.read_excel('MyFile.xlsm')
f = Path.cwd().joinpath('MyFile.xlsm')
# Adding information to the graph
wb = xl.load_workbook(f)
for sheet in wb.worksheets:
if sheet.title != 'Details':
fig.add_trace(go.Scatter(x=df1['Odo0 [m]'], y=df1['Speed Odo1 [m/s]'], mode='lines', name='Speed Odo1'),
secondary_y=False,
)
#fig.add_trace(
# go.Scatter(x=df['Distance [m]'], y=df['Speed [m/s]'], mode='lines', name='Speed'),
# secondary_y=True,
#)
# Set x-axis title
fig.update_xaxes(title_text="<b>Distance (m)<b>")
# Set y-axes titles
fig.update_yaxes(title_text="<b>Speed (m/s)<b>", secondary_y=False)
# Show plot
fig.write_html("DADDB22W0.html")
Solution 1:[1]
Ok, I solved it:
df1 = pd.read_excel('MyFile.xlsm', sheet_name='Details')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user3429343 |
