-2

I wanna graph this Excel data I have into a Python file with two axes.

This is the Excel File I have and I want to convert this data into a Python chart using Matplotlib and Pandas to read the Excel data. Note: I want the chart to have two y axes. First column is the x axis, Columns 2 and 3 are gonna be plotted on the first Y axis and 4 and 5 on the secondary y axis.

Note: Please suggest a way to extract the Excel data into python without actually making a list of the data in python

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Aaryan
  • 1
  • 1
  • [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) & [Don't advise on off-topic questions.](https://meta.stackoverflow.com/questions/276572/) – Trenton McKinney May 26 '23 at 21:04
  • For next time, read the following documentation: [Take the Tour](https://stackoverflow.com/tour), [How to ask a good question](https://stackoverflow.com/help/how-to-ask), & [On Topic](https://stackoverflow.com/help/on-topic). Always provide a [mre] with **code, data, errors, current & expected output, as [formatted text](https://stackoverflow.com/help/formatting)** & **you're expected to follow [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/a/261593/7758804) and show your effort**. – Trenton McKinney May 26 '23 at 21:05

1 Answers1

-1
import pandas as pd
import matplotlib.pyplot as plt


df = pd.read_excel("path.xlsx")

Assuming you have columny1,columny2 and an x column

fig,ax1 = plt.subplots()


ax2 = ax1.twinx() #makes 2 y-axis

ax1.plot(df["x"], df["columny1"], 'g-')
ax2.plot(df["x"], df["columny2"], 'b-')

ax1.set_xlabel('X data')
ax1.set_ylabel('Y1 data', color='g')
ax2.set_ylabel('Y2 data', color='b')

plt.show()
  • **Please suggest a way to extract the Excel data into python without actually making a list of the data in python** is off-topic. Do not answer off-topic questions. [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) & [Don't advise on off-topic questions.](https://meta.stackoverflow.com/questions/276572/) – Trenton McKinney May 26 '23 at 21:04