当前位置:网站首页>matplotlib折线图,文字显示,win10
matplotlib折线图,文字显示,win10
2022-06-26 03:45:00 【starmultiple】
matplotlib
matplotlib:最流行的Python底层绘图库,主要做数据可视化图表,名字取材于MATLAB,模仿MATLAB构建
from matplotlib import pyplot as plt#导入pyplot
#figure表示图形图标
#dpi指的是每英寸上像素点的个数
x=range(2,26,2)
#定义x轴2~24步长为2
y=[14,13,14.5,17,2,23,25,26,24,22,18,15]
#设置图片大小
fig =plt.figure(figsize=(20,8),dpi=80)
#绘图
plt.plot(x,y)
#绘制x轴刻度这里不可以直接使用0.5步长因此定义一个如下
_xtick_labels=[i/2 for i in range(4,49)]
plt.xticks(range(2,27))
plt.xticks(range(min(y),max(y)+1))
#保存图片
plt.savefig("./sig_size.png")#可以保存为svg这种矢量图格式,放大不会有锯齿
plt.show()

问题:
如果列表a表示10点到12点的每一分钟的气温,如何绘制折线图观察每分钟气温的变化情况?
a=[random.randlint(20,35) for i in range(120)]
from matplotlib import pyplot as plt
import random#随机函数
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
#调整x轴的刻度
_x=list(x)
_xtick_labels=["10点{}分".format(i) for i in range(60)]
_xtick_labels+=["11点{}分".format(i) for i in range(60)]
#取步长
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45)#rotation=45旋转45°
plt.show()

设置中文显示
法一:(推荐)
from matplotlib import pyplot as plt
import random#随机函数
#!!只要这一行
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
#调整x轴的刻度
_x=list(x)
_xtick_labels=["10点{}分".format(i) for i in range(60)]
_xtick_labels+=["11点{}分".format(i) for i in range(60)]
#取步长
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45) #rotation=45旋转45°
#添加描述信息
plt.xlabel('时间')
plt.ylabel('温度:单位(℃)')
plt.title('十点到十二点气温变化情况')
plt.show()
法二:
from matplotlib import pyplot as plt
import random#随机函数
from matplotlib import font_manager
#另外一种设置字体的方式
my_font=font_manager.FontProperties(fname='C:\WINDOWS\FONTS\MSYHL.TTC')
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
#调整x轴的刻度
_x=list(x)
_xtick_labels=["10点{}分".format(i) for i in range(60)]
_xtick_labels+=["11点{}分".format(i) for i in range(60)]
#取步长
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45,fontproperties=my_font)#rotation=45旋转45°
#添加描述信息
plt.xlabel("时间",fontproperties=my_font)
plt.ylabel("温度 单位(℃)",fontproperties=my_font)
plt.title("10点到12点每分钟的气温变化情况",fontproperties=my_font)
plt.show()

边栏推荐
- Ieda suddenly cannot find compact middle packages
- MySQL advanced part (IV: locking mechanism and SQL optimization)
- Custom parameter QR code picture combined with background picture to generate new picture node environment
- Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar
- mysql存儲過程
- “再谈”协议
- 链路监控 pinpoint
- Camera-memory内存泄漏分析(三)
- 【好书集锦】从技术到产品
- R语言与机器学习
猜你喜欢

Camera-CreateCaptureSession

商城风格也可以很多变,DIY 了解一下

用eclipse连mysql数据库出错然后出现图中的话是咋回事呀

You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead

MySQL addition, deletion, query and modification (primary level)

Small record of neural network learning 71 - tensorflow2 deep learning with Google Lab

Kotlin uses viewpager2+fragment+bottomnavigationview to implement the style of the switching module of the bottom menu bar.
![[collection of good books] from technology to products](/img/b1/a119d61ff20d19d1e42e5c243de42c.png)
[collection of good books] from technology to products

Custom parameter QR code picture combined with background picture to generate new picture node environment

. Net core learning journey
随机推荐
Introduction of mybatis invalid
go time包:秒、毫秒、纳秒时间戳输出
Classic model - Nin & googlenet
Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
使用SOAPUI访问对应的esb工程
【Flink】Flink源码分析——批处理模式JobGraph的创建
Digital twin intelligent water service, breaking through the development dilemma of sponge City
在出海获客这件事上,数字广告投放之外,广告主还能怎么玩儿?
Camera-CreateCaptureSession
C # knowledge structure
DETR3D 多2d图片3D检测框架
MySQL的视图
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
高性能算力中心 — RoCE — Overview
MySQL高級篇第一章(linux下安裝MySQL)【下】
[collection of good books] from technology to products
Navicat16 wireless trial
【LOJ#6718】九个太阳「弱」化版(循环卷积,任意模数NTT)
Class diagram
Mysql database foundation