当前位置:网站首页>matplotlib多条折线图,点散图
matplotlib多条折线图,点散图
2022-06-26 03:45:00 【starmultiple】
matplotlib折线图点散图
单折线
# coding=utf-8
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)#画xy
#设置x轴刻度
_xtick_labels=["{}岁".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
#绘制网格
plt.grid(alpha=0.2)#透明度
#展示
plt.show()
多折线
# coding=utf-8
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y1=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y2=[1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y1,label="y1")#画xy
plt.plot(x,y2,label="y2")
#设置x轴刻度
_xtick_labels=["{}岁".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
#绘制网格
plt.grid(alpha=0.2)#透明度
#添加图例
plt.legend()
#展示
plt.show()
丰富一下
# coding=utf-8
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y1=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y2=[1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y1,label="y1",color="orange",linestyle=':',linewidth=10)#画xy
plt.plot(x,y2,label="y2",color="cyan",linestyle='--',linewidth=5)
# color颜色 linestyle线条风格 linewidth线条宽度
#设置x轴刻度
_xtick_labels=["{}岁".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
#绘制网格
plt.grid(alpha=0.2)#透明度
#添加图例,使图例在左边
plt.legend(loc="upper left")
#展示
plt.show()
电散图
气温和天气的变化规律
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
y_a=[11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,23]
y_b=[26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,5,13,17,10,11,13,12,13,6]
x_a=range(1,30)
x_b=range(41,71)
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
plt.scatter(x_a,y_a,label="三月份")
plt.scatter(x_b,y_b,label="10月份")
#调整x轴的刻度
_x=list(x_a)+list(x_b)
_xtick_labels=["3月{}日".format(i) for i in x_a]
_xtick_labels+=["10月{}日".format(i-50) for i in x_b]
plt.xticks(_x[::1],_xtick_labels[::1],rotation=45)
#添加图例
plt.legend(loc="upper left")
#添加描述信息
plt.xlabel("时间")
plt.ylabel("温度")
plt.title("标题")
plt.show()
边栏推荐
- String到底能不能改变?
- How to prepare for a moving wedding
- Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
- Quanergy欢迎Lori Sundberg出任首席人力资源官
- Analysis of camera memory memory leakage (II)
- MySQL advanced Chapter 1 (installing MySQL under Linux) [2]
- 指南针app是正规的吗?到底安不安全
- Open Camera异常分析(一)
- The kotlin project is running normally and the R file cannot be found
- DETR3D 多2d图片3D检测框架
猜你喜欢
Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.
Solve the problem that the uniapp plug-in Robin editor reports an error when setting the font color and background color
String到底能不能改变?
EF core Basics
Nepal graph learning Chapter 3_ Multithreading completes 6000w+ relational data migration
Analysis of camera memory memory leakage (II)
ABP framework Practice Series (II) - Introduction to domain layer
After Ali failed to start his job in the interview, he was roast by the interviewer in the circle of friends (plug)
MySQL development environment
智能制造学习记录片和书籍
随机推荐
The style of the mall can also change a lot. DIY can learn about it
Quanergy欢迎Lori Sundberg出任首席人力资源官
[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours
Flask入门
Qixia fire department carries out fire safety training on construction site
. Net core learning journey
progress bar
mysql 常用语句
xml 解析bean工具类
Classic model – RESNET
XML parsing bean tool class
Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
2020 summary: industrial software development under Internet thinking
Prism framework project application - Navigation
使用SOAPUI访问对应的esb工程
智能制造学习记录片和书籍
View of MySQL
Evaluation - analytic hierarchy process
JS to achieve the effect of text marquee
360 second understanding of smartx hyper converged infrastructure