Matplotlib的部分方法

关于matplotlib的一些方法

关于figure
关于axes
关于legend
关于plot

关于figure返回顶部

figure参考blog: https://blog.csdn.net/zjyklwg/article/details/79477261

import matplotlib.pyplot as plt
		#创建一个图形实例对象
		#figure = plt.figure()
		#01.figure参数:num=图形界面的名字;figsize=图形界面的大小
		#figure_0 = plt.figure(num="figsize=3*1",figsize=(3,1))
		figure_1 = plt.figure(num="figsize=5*5",figsize=(5,5))
		#02.figure参数:dpi=图形分辨率;facecolor=背景色;edgecolor=边框颜色
		figure_3 = plt.figure(num="figure_3",figsize=(6,6),dpi=70,facecolor="#3498db",edgecolor="#2c3e50")
		#给最近的窗口绘制坐标轴(范围在0~20)
		plt.xlim(0,20)
		plt.ylim(0,20)
		plt.show()
		plt.close()

关于axes 返回顶部

参考blog:https://blog.csdn.net/qq_39949963/article/details/105880235
一种类似于figure的画布对象,不过他是嵌套在figure中的,相当于JavaSwing中的panel,从下面的列子可以看出差别

import matplotlib.pyplot as plt
		#这里一般用plt.subplots来设置画布,返回画布和子画布
		#将figure分块,nrow设置行数,ncols设置列数
		figure , axes = plt.subplots(nrows=1,ncols=2)
		x = np.linspace(0,10,1000)
		axes[0].plot([1,2,3],[2,4,6])
		axes[1].plot(x, np.sin(x))

关于legend返回顶部

参考blog:https://blog.csdn.net/jasonzhoujx/article/details/81773530

'''
一段官方的文档注释:
loc:
The location of the legend.
ncol: 
The number of columns that the legend has.
fontsize: 
he font size of the legend.
labelcolor:
Sets the color of the text in the legend.
frameon :
Whether the legend should be drawn on a patch (frame)
fancybox :
Whether round edges should be enabled
shadow:
Whether to draw a shadow behind the legend
framealpha:
The alpha transparency of the legend's background
facecolor:
The legend's background color
edgecolor:
The legend's background patch edge color
title:
The legend's title
title_fontsize:
The font size of the legend's title.
borderpad:
The fractional whitespace inside the legend border, in font-size units.
labelspacing: 
The vertical space between the legend entries, in font-size units.
'''
import matplotlib.pyplot as plt
	figure = plt.figure(figsize=(5,5),facecolor='#2ecc71')
	x = np.arange(0,2*np.pi,0.5)
	y_sin = np.sin(x)
	y_cos = np.cos(x)
	plt.plot(x,y_sin,linestyle='-',marker='o',label ='y_sin' ,color='blue')
	plt.plot(x,y_cos,linestyle='-',marker='^',label ='y_cos' ,color='red')
	#全部默认配置
	plt.legend()
	#loc指定图例的位置,frameon指定是否去掉外边框,ncol指定列数
	plt.legend(loc='upper right',frameon=False,ncol=2)
	#fancybox指定是否为圆角边框,framealpha指定透明度,shadow指定是否为阴影,
	plt.legend(fancybox=True,framealpha=0.6,shadow=True,borderpad=1)
	#当标签变多的时候
	y = np.sin(x[:, np.newaxis] + np.pi * np.arange(0, 2, 0.5))
	#print(y)
	lines = plt.plot(x, y)
	#print(lines)
	plt.legend(lines[:2],['first','second'])
	plt.show()

关于plot返回顶部

参考blog:https://blog.csdn.net/henni_719/article/details/77370434

#简答来说就是绘制曲线
import matplotlib.pyplot as plt
	x = np.arange(-2*np.pi,2*np.pi,0.1)
	y_1 = np.sin(x)
	y_2 = np.cos(x)
	y_3 = np.abs(np.sin(x))
	#前面两个参数为传进来的数据集,线条样式或标记样式,线条颜色
	'''plt.plot(x,y_1,'1')
	plt.plot(x,y_2,'2')
	plt.plot(x,y_3,'x','r')'''
	#linestyle线条样式,marker标记样式,markerfacecolor标记点的颜色,markersize标记点的大小
	#plt.plot(x,y_3,linestyle='--',label="line",marker = '*',markerfacecolor='r',markersize=8)
	#绘制带锯状的曲线
	plt.plot(x,y_1,'o--',markerfacecolor='b',label='y_1_line',linewidth=2,antialiased=False)
	plt.plot(x,y_2,'o--',label="y_2_line")
	plt.legend(loc='upper right')
	#画一个半径为1的圆,用极坐标的公式
	figure=plt.figure(num="circle",figsize=(5,5),facecolor='#ecf0f1')
	axes = figure.add_subplot(1,1,1)
	thetas = np.arange(0,2*np.pi,0.01)
	plt.xlim(-1,1)
	plt.ylim(-1,1)
	x_ = np.cos(thetas)
	y_ = np.sin(thetas)
	plt.plot(x_,y_,linestyle='-',color='blue')
	plt.plot(x_,-y_,linestyle='-',color='blue')
	plt.grid(True)
	plt.show()

参考连接丢失(21.4.10)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值