matplotlib基本使用(矩形图、饼图、热力图、3D图)

使用matplotlib画简单的图形:

 

#-*- coding:utf-8 -*-
from numpy.random import randn
import matplotlib.pyplot as plt

fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
plt.plot(randn(50).cumsum(),'k--')
ax2=fig.add_subplot(2,2,2)
#bins越大矩形越窄 alpha表示颜色深度
ax2.hist(randn(10000), bins  = 30, color = 'red', alpha = 1)
ax3=fig.add_subplot(2,2,3)
plt.plot([1.5, 2, 4, -2, 1.6])
plt.show()

 

运行结果:

 

散点图

 

#-*- coding:utf-8 -*-
from pylab import *
import matplotlib.pyplot as plt

mpl.rcParams['font.sans-serif'] = ['SimHei']

n = 1024
X = np.random.normal(0,1,n)
Y = np.random.normal(0,1,n)

for i in range(1,10):
    scatter(i, i)
plt.title(u"散点图",color='red')
show()

 

 

pyplot.subplots有几个选项
nrows:subplot的行数
ncols:subplot的列数
sharex:所有subplot共享x轴刻度
sharey:所有subplot共享Y轴刻度

 

#-*- coding:utf-8 -*-
from  numpy.random import randn
from matplotlib import pyplot as plt

fig,axes=plt.subplots(2,2,sharex=True,sharey=True)

for i in range(2):
    for j in range(2):
        axes[i,j].hist(randn(50),bins=50,color='red',alpha=1)
plt.show()

 

 

矩阵图

 

 

#-*- coding:utf-8 -*-
from pylab import *

#使用中文
mpl.rcParams['font.sans-serif'] = ['SimHei']
#显示负号
matplotlib.rcParams['axes.unicode_minus'] = False

n=32
list1=[i for i in range(1,33)]
list2=[i for i in range(-32,0)]
n= np.arange(n)
xlim(-1,32)
ylim(-35,35)
xlabel(u'每个城市招聘人数'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值