python:画折线图

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

# 设置新宋体字体的路径
font_path = 'D:/reportlab/simsun/simsun.ttf'

# 加载新宋体字体
prop = FontProperties(fname=font_path)

"""
# 读取 xlsx 文件
df = pd.read_excel('your_excel_file.xlsx')

# 假设 xlsx 文件包含两列,一列是类别,一列是数值
categories = df['Category'].tolist()
values = df['Value'].tolist()
"""
#以上是自己的数据,可以加上这个。



categories = [1, 2, 3, 4, 5]
values = [10, 15, 13, 18, 16]
# 创建柱状图,并设置颜色
plt.plot(categories, values)

# 添加标题和标签,并使用新宋体字体
plt.title('柱状图示例', fontproperties=prop)
plt.xlabel('类别', fontproperties=prop)
plt.ylabel('数值', fontproperties=prop)

# 设置刻度字体
plt.xticks(fontproperties=prop)
plt.yticks(fontproperties=prop)

# 显示图形
plt.show()

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-05-10 12:24:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-10 12:24:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-10 12:24:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-10 12:24:02       18 阅读

热门阅读

  1. 机器学习笔记-02

    2024-05-10 12:24:02       8 阅读
  2. Centos7.9搭建yum仓库

    2024-05-10 12:24:02       9 阅读
  3. C++面向对象学习笔记四

    2024-05-10 12:24:02       12 阅读
  4. Linux学习笔记2

    2024-05-10 12:24:02       12 阅读
  5. SpringBoot学习记录(1)

    2024-05-10 12:24:02       9 阅读
  6. leetcode题目1

    2024-05-10 12:24:02       10 阅读
  7. C++ 509. 斐波那契数

    2024-05-10 12:24:02       10 阅读