python pyplot用法_matplotlib.pyplot基本用法

查看matplot配置文件:

import matplotlib

print(matplotlib.matplotlib_fname())

from pylab import *

zhfont = mpl.font_manager.FontProperties(fname='/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc')

单个图像

plt.figure(figsize=(w, h)) #创建对象,并指定宽度w高度h,默认像素为80ppi,单位为100像素?还是英寸?

plt.plot([1,2,3,4], [1,4,9,16], 'ro') #指定xy坐标,显示样式

plt.axis([0, 6, 0, 20]) #指定横纵轴 [xmin, xmax, ymin, ymax]

plt.xlabel('Smarts'),plt.ylabel('Probability') #设置 x 轴和 y 轴的文字

plt.title('Histogram of IQ')

设置文字注释: plt.text(60, .025, r'$\mu=100,\ \sigma=15$')

不显示坐标轴: plt.axis('off')

显示图像: plt.show()

保存图像: fig.saveimg(imgname)

多幅图中多个图像

plt.xx操作是针对当前fig对象,通过plt.figure(str)切换到需要操作的图像,通过plt.subplot(num)切换到子图像

subplot(236): 图像总数为2行x3列,中的第6幅图

f14a588bd474

23x

import matplotlib.pyplot as plt

plt.figure(1) # the first figure,也可以为字符串

plt.subplot(211) # the first subplot in the first figure

plt.plot([1, 2, 3])

plt.subplot(212) # the second subplot in the first figure

plt.plot([4, 5, 6])

plt.figure(2) # a second figure

plt.plot([4, 5, 6]) # creates a subplot(111) by default

plt.figure(1) # figure 1 current; subplot(212) still current

plt.subplot(211) # make subplot(211) in figure1 current

plt.title('Easy as 1, 2, 3') # subplot 211 title

多幅子图:

fig=plt.figure()

ax1=fig.add_subplot(311)

设置横坐标为[0, 100]

ax1.set_xlim(0,100)

设置x轴标签

ax1.set_xlabel('x')

设置子图之间的距离

调整子图的横向和纵向间隔

fig.subplots_adjust(wspace=0.5, hspace=0.3)

关于共享横轴和总轴

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值