当前位置:网站首页>matplotlib绘制多折线图(解决matplotlib中文无法显示问题)
matplotlib绘制多折线图(解决matplotlib中文无法显示问题)
2022-07-17 20:33:00 【孙志攀】
折线图的概念
(1)标记:折线
(2)必备的视觉通道:拐点的x,y坐标
(3)常见的视觉通道:色彩、宽度、形态(虚实,箭头等)
(4)适用场景:显示随时间或有序类别而变化的趋势、也可以显示数据点表示某个数据值,或者不显示数据点来表示某个类别的数据趋势等。大量应用于分析数据走势和对比关系上。
1.折线图绘画某城市11点到12点每分钟温度变化,温度范围15–18(单线条)
1. 准备数据 x,y
import random #导入随机数库
x=range(60)
y=[random.uniform(15,18) for i in x] #对应每分钟设置一个温度
2. 导入matplotlib库,绘制折线图
import matplotlib
import matplotlib.pyplot as plt #导入画图库
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文
#创建画布,设置画布大小以及清晰度
plt.figure(figsize=(20,8),dpi=100)
#绘制折线图
plt.plot(x,y)
#修改y轴刻度值,使其显示范围0—40,每隔5度显示一个数值
plt.yticks(range(0,40,5))
#修改X轴刻度,让新刻度与原刻度一一对应
x_lable=["11点{}分".format(i) for i in x]
plt.xticks(x[::5],x_lable[::5])
#让画布添加网格显示
plt.grid(linestyle='--',alpha=0.5)
#添加 X,Y轴标签,图像名称
plt.xlabel('时间')
plt.ylabel('温度')
plt.title("11点到12点每分钟温度变化图")
plt.show()
3.结果:

2.多线条绘制两城市11时到12时温度变化(多线条)
1.准备数据 x_1,y_1,x_2,y_2
import random #导入随机数库
x_1=range(60)
x_2=range(60)
y_1=[random.uniform(15,18) for i in x] #对应每分钟设置一个温度
y_2=[random.uniform(5,10) for i in x]
2. 导入matplotlib库,绘制折线图
import matplotlib
import matplotlib.pyplot as plt #导入画图库
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文
#创建画布,设置画布大小以及清晰度
plt.figure(figsize=(20,8),dpi=100)
#绘制折线图
plt.plot(x_1,y_1,color='c',linestyle='--',label='城市一')
plt.plot(x_2,y_2,color='b',label='城市二')
#修改y轴刻度值,使其显示范围0—40,每隔5度显示一个数值
plt.yticks(range(0,40,5))
#修改X轴刻度,让新刻度与原刻度一一对应
x_lable=["11点{}分".format(i) for i in x]
plt.xticks(x[::5],x_lable[::5])
#让画布添加网格显示
plt.grid(linestyle='--',alpha=0.5)
#添加 X,Y轴标签,图像名称
plt.xlabel('时间')
plt.ylabel('温度')
plt.title("11点到12点每分钟温度变化图")
#显示图例
plt.legend()
plt.show()
3.结果:

matplotlib各颜色名称如下,输入对应颜色名称可以获得不同颜色线条
边栏推荐
- Analyze and hook sshd to hijack password
- Introduction:Multiple DataFrames
- 009 面试题 SQL语句各部分的执行顺序
- [dynamic programming] - longest ascending subsequence model
- Chrome plug-ins for information collection
- [7.15] code source - [neat array 2] [ternary cycle] [reverse pair on tree] [sequence of cochlea]
- FreeRTOS implementation of idle tasks and blocking delay
- Create a new Eureka client
- 96. 不同的二叉搜索树
- "Podcast" \ # 392 original Tang Lang original food: MIDSUMMER night, ma Sha, kebab, Kebab
猜你喜欢

Comprehensive analysis of C language multimedia open source framework GStreamer

Take a look at try{}catch{}

A Classical Review of nonconvex optimization problems from Symmetry to Geometry, Rochester University, etc.

Ranking of top ten ERP software systems at home and abroad!
![[code hoof set novice village question 600] format specifier of float and double](/img/19/433f794617f3c3c72732f1a4efe252.png)
[code hoof set novice village question 600] format specifier of float and double

uniapp 高德地图定位功能

欧奈尔的RPS曲线的编制方法(陶博士原创)

Event preview | Apache Doris x Apache seatunnel joint meetup to start registration!

Class 3 practice

Uniapp Gaode map positioning function
随机推荐
unity 实现UI-背包装备拖拽功能
Analyze and hook sshd to hijack password
[cann training camp] Introduction to basic knowledge of shengteng AI
【6.15】Codeforces Round #798 (Div. 2)
FreeRTOS-空闲任务和阻塞延时的实现
ImportError: DLL load failed while importing win32api: 找不到指定的程序。
【ACWing】2492. HH Necklace
[7.13] code source - [hungry meals] [path count 2] [function sum]
No.3汇编进阶
Ranking of top ten ERP software systems at home and abroad!
[learn FPGA programming from scratch -53]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Xilinx)
Interview records
"Technology podcast month" day 10: meta podcast: talk about Podcasting
Microservice calling component feign practice
【ACWing】2521. Count colors
Introduction:Multiple DataFrames
AcWing 136. 邻值查找
AcWing 134. 双端队列
Introduction:Multiple DataFrames
The cloud audit service CTS is a paid service. The paid items include the opening of tracker, event tracking, storage and retrieval of events within 7 days and other related fees