matplotlib画布中属性设置常用函数及其说明

article/2025/10/12 4:14:16

绘图时设置坐标轴属性

data = np.arange(0,1,0.01)
plt.title('my lines example')
plt.xlabel('x')
plt.ylabel('y')
plt.xlim(0,1)
plt.ylim(0,1)
plt.xticks([0,0.2,0.4,0.6,0.8,1])
plt.yticks([0,0.2,0.4,0.6,0.8,1])
plt.tick_params(labelsize = 12)
plt.plot(data,data**2)
plt.plot(data,data**3)
plt.legend(['y = x^2','y = x^3'])
plt.show()

 包含子图绘制的基础语法

data = np.arange(0,np.pi * 2,0.01)
fig1 = plt.figure(figsize=(9,7),dpi=90)
ax1 = fig.add_subplot(1,2,1)
plt.title('line example')
plt.xlabel('x')
plt.ylabel('y')
plt.xlim(0,1)
plt.ylim(0,1)
plt.xticks([0,0.2,0.4,0.6,0.8,1])
plt.yticks([0,0.2,0.4,0.6,0.8,1])
plt.plot(data,data**2)
plt.plot(data,data**3)
plt.legend(['y = x^2','y = x^3'])
ax1 = fig1.add_subplot(1,2,2)
plt.title('sin-cos')
plt.xlabel('x')
plt.ylabel('y')
plt.xlim(0,np.pi*2)
plt.ylim(-1,1)
plt.xticks([0,np.pi/2,np.pi,np.pi*(3/2),np.pi*2])
plt.yticks([-1,-0.5,0,0.5,1])
plt.plot(data,np.sin(data))
plt.plot(data,np.cos(data))
plt.legend(['sin','cos'])
plt.show()

 关于plt.legend()参数 loc说明

0:'best'       1:'upper right'     2:'upper left'    3:'lower left'     4:'lower right'    5:'right'    6:'center left'
7:'center right'     8:'lower center'   9:'upper center'      10:'center'plt.legend(loc = 'best,frameon = False)
#去掉图里边框,推荐使用
plt.legend(loc = 'best,edgecolor = 'blue)
#设置图例边框颜色
plt.legend(loc = 'best,facecolor = 'blue)
#设置图例背景颜色,若无边框,参数无效

绘图显示和保存函数

plt.savefig
#保存绘制的图片,可以指定图片的分辨率,边缘的颜色等参数
plt.show
#在本机显示图形

figure.savefig()选项及说明

fname
#包含文件路径或python文件型对象的字符串。图片格式是从文件扩展名中推断出来的(例如PDF格式的.pdf)
dpi
#设置每英寸点数的分辨率,默认为100
facecolor.edegecolor
#子图之外的图形的背景颜色,默认是‘w'(白色)
format
#文件格式('png','pdf','svg','ps'等)
bbox_inches
#要保存的图片范围,设置为'tight'则去除图片周围的空白

查看matplotlib的rc参数

print(plt.rcParams())

全局参数定制

 

rc参数                             解释                          取值
lines.linewidth                    线条宽度                      取0~10的数值,默认为1.5
lines.linestyle                    线条样式                      取“-”,“--”,“-.”,“:”4种,默认为“-”
lines.maker                        线条上点的形状                 可取“o”,“D”等20种,默认为None
lines.markersize                   点的大小                      取0~10的数值,默认为1

线条样式lines.linestyle的取值

linestyle取值                               意义
-                                           实线
--                                          长虚线
-.                                          点线
:                                           短虚线

lines.marker参数的取值

marker取值                                      意义
'o'                                             圆圈
'D'                                             菱形
'h'                                             六边形1
'H'                                             六边形2
'-'                                             水平线
'8'                                             八边形
'p'                                             五边形
','                                             像素
'+'                                             加号
'None'                                          无
'.'                                             点
's'                                             正方形
'*'                                             星号
'd'                                             小菱形
'v'                                             一角朝下的三角形
'<'                                             一角朝左的三角形
'>'                                             一角朝右的三角形
'^'                                             一角朝上的三角形
'|'                                             竖线
'x'                                             X

rc参数设置示例 1

fig,ax = plt.subplots()
#配置中文显示
plt.rcParams['font.family'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
def f(t):return np.cos(2 * np.pi * t)
x1 = np.arange(0.0,4.0,0.5)
x2 = np.arange(0.0,4.0,0.01)
plt.figure(1)
plt.subplot(2,2,1)
plt.plot(x1,f(x1),'bo',x2,f(x2),'k')
plt.title('子图1')
plt.subplot(2,2,2)
plt.plot(np.cos(2 * np.pi * x2),'r--')
plt.title('子图2')
plt.show()

rc参数设置示例2

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(np.random.randn(30).cumsum(),color = 'k',linestyle = 'dashed',marker = 'o',label = 'one')
ax.plot(np.random.randn(30).cumsum(),color = 'k',linestyle = 'dashed',marker = '+',label = 'two')
ax.plot(np.random.randn(30).cumsum(),color = 'k',linestyle = 'dashed',marker = 'v',label = 'three')
ax.legend(loc = 'best')

 

 用set_xticks设置刻度

ax.set_xticks([0,5,10,15,20,25,30,35])

 用set_sticklabels改变刻度

ax.set_xticklabels(['x1','x2','x3','x4','x5'],rotation = 30,fontsize = 'large')

其中rotation参数表示X坐标标签的旋转角度;fontsize为字号,可以取值为“xx-small","x=small","small","mediaum" ,"large","x-large","xx-large","larger","smaller","None"


http://chatgpt.dhexx.cn/article/UU1fKStR.shtml

相关文章

MATLAB里面size什么意思,matlab中的makersize是什么意思

MATLAB中的绘图语言 plot(j,len1-i,ro,MarkerS...参数那么多&#xff0c;有点晕啊&#xff0c;每个参数代表什么意思啊&#xff1f;&#xff1f;&#xff1f; 前面的j和len1-i...plot(...,PropertyName,PropertyValue,...) plot(j,len1-i,ro,MarkerSize,10,LineWidth,2); 其中j…

matplotlib画图自定义marker

文章目录 matplotlib画图自定义markermarker的特点通过插入图片实现自定义marker通过Path实现自定义marker matplotlib画图自定义marker 在matplotlib工具箱中可以画marker的高级作图函数一共有两个&#xff0c;分别为plot和scatter&#xff0c;可以画出多种marker。但如果需要…

plot函数的应用

这一部分是关于plot函数的简单应用&#xff0c;下面附有一段代码示例&#xff0c;详情请见代码及其注释。 import matplotlib as mlp from PIL import Image from pylab import * import os image_path "D:/warehouse/image_list" # 储存照片的路径 os.chdir(imag…

pyplot散点图标记大小

本文翻译自&#xff1a;pyplot scatter plot marker size In the pyplot document for scatter plot: 在散点图的pyplot文档中&#xff1a; matplotlib.pyplot.scatter(x, y, s20, cb, markero, cmapNone, normNone,vminNone, vmaxNone, alphaNone, linewidthsNone,facetedTr…

matplotlib:marker类型/size/空心

marker类型 plt.plot(RSEP_data, colorcolor[1], labelRSEP, linestyle--, markerv, markerfacecolornone, markersize10)

python pyplot 宽高等比_如何使pyplot分散中的markersize不依赖于图形的比例?

我在做一个模拟&#xff0c;我想用pyplot来显示。在模拟中&#xff0c;有一些圆在移动&#xff0c;当它们重叠时会发生一些事情。当我尝试用pyplot显示这个时&#xff0c;标记的大小不正确。在 我试过改变标记的大小&#xff0c;但没有解决问题。经过一些测试&#xff0c;我意识…

详解Axes()中的markersize

在Matplotlib中&#xff0c;Axes对象的markersize参数是指绘制图形中marker&#xff08;如散点图中的点&#xff09;大小的参数。这个参数指定marker的直径的长度&#xff0c;单位为像素或点&#xff08;pt&#xff09;。具体来说&#xff0c;它控制marker在x轴和y轴方向上的大…

Matlab scatter/plot绘制图时,单点的'MarkerSize'与空间位置的关系

scatter scatter(axes, x, y, sz, ‘Marker’, ‘o’)&#xff1b; scatter()函数中参数sz决定’Marker’&#xff08;即’o’&#xff09;的标记面积&#xff08;大小&#xff09;&#xff0c;默认单位是平方磅&#xff08;points&#xff09;&#xff0c;o’在坐标轴中的宽度…

markersize

为什么80%的码农都做不了架构师&#xff1f;>>> plot([1,2,3,4],[2,5,6,9],c-pentagram,markersize,35) %pentagram:是五角星,c代表颜色亮蓝;-代表线性实线,markersize(即五角星的大小)为35 下面是画图的颜色和线型&#xff0c;matlab 中画图的颜色 字母 颜色…

plot中的 markersize

‘markersize’ plot([0,1,2,3,4],[0,2,5,6,9],‘c-pentagram’,‘markersize’,15) 画图的命令是&#xff1a; marker是图上画上点的地方表上符号&#xff0c;不如点&#xff0c;方框&#xff0c;圆框&#xff0c;十字&#xff0c;星号&#xff0c;等等 后面的size就是其大小…

matlab2015的marker,matlab中markersize什么意思

matlab中如何调整plot多变量绘图中的markersize MATLAB中的绘图语言 plot(j,len1-i,ro,MarkerS...参数那么多&#xff0c;有点晕啊&#xff0c;每个参数代表什么意思啊&#xff1f;&#xff1f;&#xff1f; 前面的j和len1-iplot(...,PropertyName,PropertyValue,...) plot(j,l…

matlab中marker太密,markersize_想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_

广告位API接口通信错误,查看德得广告获取帮助 想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_size’是什么意思 就是标准尺寸。 ‘markersize’plot([0,1,2,3,4],[0,2,5,6,9],c-pentagram,markersize,15) 画图的命令是:marker是图上画上点的地方表上符号,不如点,方框,…

matlab里markersize,Matlab scatter/plot绘制图时,单点的'MarkerSize'与空间位置的

Matlab scatter/plot绘制图时,单点的MarkerSize与空间位置的 Matlab scatter/plot绘制图时,单点的MarkerSize与空间位置的关系 scatter scatter(axes, x, y, sz, ‘Marker’, ‘o’); scatter()函数中参数sz决定’Marker’(即’o’)的标记面积(大小),默认单位是平方磅(poin…

[MATLAB学习笔记] MATLAB里 ‘Markersize’ 设置的值是‘Marker_size’

Markersize意思是标记尺寸&#xff0c;那么 Marker_size 的值代表的就是标记尺寸的大小。 例如在 plot 作图中&#xff0c;事先定义两个数据 x-pi:0.5:pi , ysin(x) ,运行作图命令 plot(x,y,o,Markersize,12) o 的意思为坐标点用圆圈标记&#xff0c;那么 Markersize 的意思…

Spring Authorization Server的使用

Spring Authorization Server的使用 一、背景二、前置知识三、需求四、核心代码编写1、引入授权服务器依赖2、创建授权服务器用户3、创建授权服务器和客户端 五、测试1、授权码流程1、获取授权码2、根据授权码获取token3、流程演示 2、根据刷新令牌获取token3、客户端模式4、撤…

SpringSecurityOAuth已停更,来看一看进化版本Spring Authorization Server

Spring Authorization Server是Spring Security OAuth的进化版本&#xff0c;Spring Security OAuth官方已经宣布“End of Life”了。Spring Security OAuth使用的是OAuth2.0标准而Spring Authorization Serve引入了对OAuth 2.1和OpenID Connect 1.0规范的支持&#xff0c;并提…

Spring Authorization Server1.0 介绍与使用

一、版本使用 1、Java&#xff1a;17或者更高的版本。 2、springboot 3.0 3、Spring Authorization Server 1.0版本。 <dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-oauth2-authorization-server</ar…

curl php authorization,PHP CURL 执行 Authorization 请求

PHP CURL 扩展可以帮助我们快速实现HTTP请求。查看更多: 博客原文 在使用豆瓣OAuth登录接口时&#xff0c;我们需要发送这样的HTTP REQUEST 请求:GET /v2/user/~me HTTP/1.1 Host: https://api.douban.comAuthorization: Bearer a14afef0f66fcffce3e0fcd2e34f6ff4 在命令行中我…

spring authorization server使用说明

spring authorization server使用说明 相关依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!-- 授权客户端 --><dependency><groupId…

Spring Authorization Server 系列(二)获取授权码

Spring Authorization Server 系列&#xff08;二&#xff09;获取授权码 概述获取授权码获取授权码的url逻辑解析匹配url参数解析 概述 Spring Authorization Server 是基于 OAuth2.1 和 OIDC 1.0 的。 只有 授权码&#xff0c;刷新token&#xff0c;客户端模式。 获取授权码…