
python 读取excel文件并画折线图
【代码】python 读取excel文件并画折线图。
·
import pandas as pd
from pylab import *
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
# Load the Excel file
#此处“\”需要转义
file_path = '文件目录\\dddd.xlsx'
# Read the Excel file
df = pd.read_excel(file_path)
# Extract the required columns for plotting
\\df['列标题']
original_x = df['x原始坐标']
predicted_x = df['x预测坐标']
# True value
true_value_x=730
true_value_y =920
true_value_d =1140
true_value_a = 14
# Create a line plot
plt.figure(figsize=(10, 6))
mpl.rcParams['font.sans-serif'] = ['SimHei']
plt.plot(original_x, label='x', marker='o')
plt.plot(predicted_x, label='x预测', marker='x')
plt.axhline(y=true_value_x, color='r', linestyle='-', label='真实值')
# Add labels and title
plt.xlabel('Index')
plt.ylabel('Coordinates')
plt.title('x坐标 vs 预测坐标')
plt.legend()
//保存图片
plt.savefig('./x原始vs预测.jpg')
# Display the plot
plt.show()
更多推荐
所有评论(0)