当前位置:网站首页>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()

边栏推荐
- "Renegotiation" agreement
- Camera-memory内存泄漏分析(三)
- You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead
- Analysis of camera memory memory leakage (II)
- After Ali failed to start his job in the interview, he was roast by the interviewer in the circle of friends (plug)
- mysql 常用语句
- 816. 模糊坐标
- go time包:秒、毫秒、纳秒时间戳输出
- Open camera anomaly analysis (I)
- Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.
猜你喜欢

ASP. Net startup and running mechanism

ABP framework Practice Series (I) - Introduction to persistence layer

优化——多目标规划

C # knowledge structure

Camera-CreateCaptureSession
![[LOJ 6718] nine suns' weakened version (cyclic convolution, arbitrary modulus NTT)](/img/fd/0c299b7cc728f2d6274eea30937726.png)
[LOJ 6718] nine suns' weakened version (cyclic convolution, arbitrary modulus NTT)

Open camera anomaly analysis (I)

【Flink】Flink源码分析——批处理模式JobGraph的创建

Multimedia elements, audio, video

Uni app custom navigation bar component
随机推荐
DETR3D 多2d图片3D检测框架
EF core Basics
Binary search method
QPS的概念和实现
816. fuzzy coordinates
MySQL高级部分( 四: 锁机制、SQL优化 )
Run multiple main functions in the clion project
Three level menu applet
Uni app, the text implementation expands and retracts the full text
The kotlin project is running normally and the R file cannot be found
What does virtualization mean? What technologies are included? What is the difference with private cloud?
Pay attention to the entrance components of official account in the applet
Communication mode between processes
2022.6.23-----leetcode.30
js实现文字跑马灯效果
【LOJ#6718】九个太阳「弱」化版(循环卷积,任意模数NTT)
Popupwindow utility class
Solve the problem that the uniapp plug-in Robin editor reports an error when setting the font color and background color
2020 summary: industrial software development under Internet thinking
解决uniapp插件robin-editor设置字体颜色和背景颜色报错的问题