linux matplotlib 库的运用

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.gridspec as gridspec
from matplotlib.font_manager import *
myfont=FontProperties(fname='/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf')
#根据自己的系统选择 在root命令行键入fc-list :lang=zh 查看本机所支持的中文字体
#matplotlib文本显示与分区
'''
1) matplotlib.rcParams['font.family]=myfont 全局设置(不推荐)
里面的参数可以是 font.family font.size font.style--->normal italic(斜体)

'''
#2)局部设置

gs=gridspec.GridSpec(3,3)
ax1=plt.subplot(gs[0,:])
ax2=plt.subplot(gs[1,-1])
ax3=plt.subplot(gs[1,:-1])#[1,-2]+[1,-3]
ax4=plt.subplot(gs[2,:],projection='polar')

ax1.set_title('一个简单的$y=cos(2\pi x)$',fontproperties=myfont)
ax1.arrow(0.2,0.5,1,0.3,facecolor='red',edgecolor='green',shape='right',width=0.1)#shape-->full right left width
ax1.annotate('$y=cos(2\pi x)$',xy=(0.5,0.6), xytext=(2,1),arrowprops=dict(facecolor='red',shrink=0.05,width=1))
x=np.arange(-np.pi*2,np.pi*2,np.pi/100)
y=np.cos(x)
ax1.plot(x,y,'r--',linewidth=0.6)
ax1.grid(True)
sizes=[15,30,15,40]
explode=[0.1,0,0,0]
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
print(type(labels))
ax3.pie(x=sizes,explode=explode,labels=labels,autopct='%1.1f%%')#autopct=fmt%percent symbol(%)  fmt-->%1.1f


N=20
left=np.linspace(0,2*np.pi,N,endpoint=False)#扇形的起始角度
radii=10*np.random.rand(N)#扇形半径
width=np.pi/4*np.random.rand(N)#扇形弧长
bars=ax4.bar(left=left,height=radii,width=width,bottom=0)
for r,bar in zip(radii,bars):
    bar.set_facecolor(plt.cm.viridis(r/10))
    bar.set_alpha(0.5)
plt.show()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值