Python 如何使用matplotplib为excel工作簿中的不同工作表绘制不同的图形?
我有3张不同的表格(表格1,表格2,表格3),每个表格有2列X,Y 我想为这三张纸分别绘制3张不同的图表。Python 如何使用matplotplib为excel工作簿中的不同工作表绘制不同的图形?,python,excel,pandas,matplotlib,graph,Python,Excel,Pandas,Matplotlib,Graph,我有3张不同的表格(表格1,表格2,表格3),每个表格有2列X,Y 我想为这三张纸分别绘制3张不同的图表。 如何在PYthon中使用Pandas和Matplotlib打印它们?Pandas包具有Excel读取和打印功能。一种可能的解决办法如下: # Read all sheets of the workbook sheets = pd.read_excel("/path/to/your/datafile.xlsx", sheet_name=None) for sheet_name, df in
如何在PYthon中使用Pandas和Matplotlib打印它们?Pandas包具有Excel读取和打印功能。一种可能的解决办法如下:
# Read all sheets of the workbook
sheets = pd.read_excel("/path/to/your/datafile.xlsx", sheet_name=None)
for sheet_name, df in sheets.items():
df.plot(x='x', y='y', title=sheet_name)
这给了我一系列看起来像这样的图像(但还有其他页面标题——我在三张页面上复制了数据)
如果您只需要特定的工作表名称,可以使用
for sheet_name in ("Sheet1", "Sheet2", "Sheet3"):
df = sheet[sheet_name]
df.plot(x='x', y='y', title=sheet_name)
编辑:提问者报告说,问题中的特定文件已使用以下代码成功处理
for i in range(3):
df = pd.read_excel(excel_file, sheet_name=i)
f = Figure(figsize=(3, 2), dpi=100)
a = f.add_subplot(111)
a.plot(df['x'], df['y'], 'ro')
熊猫软件包具有Excel读取和打印功能。一种可能的解决办法如下:
# Read all sheets of the workbook
sheets = pd.read_excel("/path/to/your/datafile.xlsx", sheet_name=None)
for sheet_name, df in sheets.items():
df.plot(x='x', y='y', title=sheet_name)
这给了我一系列看起来像这样的图像(但还有其他页面标题——我在三张页面上复制了数据)
如果您只需要特定的工作表名称,可以使用
for sheet_name in ("Sheet1", "Sheet2", "Sheet3"):
df = sheet[sheet_name]
df.plot(x='x', y='y', title=sheet_name)
编辑:提问者报告说,问题中的特定文件已使用以下代码成功处理
for i in range(3):
df = pd.read_excel(excel_file, sheet_name=i)
f = Figure(figsize=(3, 2), dpi=100)
a = f.add_subplot(111)
a.plot(df['x'], df['y'], 'ro')
谢谢你的回答!下面的代码是我为得到范围(3)内I的3个不同图形而编写的:df=pd.read_excel(excel_文件,sheet_name=I)f=fig(figsize=(3,2),dpi=100)a=f.add_子图(111)a.plot(df['x'],df['y'],'ro')总是很高兴得到积极的反馈,谢谢。我已将您的代码添加到答案中。谢谢您的回答!下面的代码是我为得到范围(3)内I的3个不同图形而编写的:df=pd.read_excel(excel_文件,sheet_name=I)f=fig(figsize=(3,2),dpi=100)a=f.add_子图(111)a.plot(df['x'],df['y'],'ro')总是很高兴得到积极的反馈,谢谢。我已将您的代码添加到答案中。