matplotlib的美化操作

引包


import numpy as np
import matplotlib.pyplot as plt

 美化操作

# print(plt.style.available)不同的美化风格
# ['Solarize_Light2', '_classic_test_patch', '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'tableau-colorblind10']
plt.style.use('Solarize_Light2')
# 生成四个子图
fig,axes=plt.subplots(2,2)
# 四个子图坐标分别赋给四个对象
ax1,ax2,ax3,ax4=axes.ravel()
# 第一个散点图
n=50
x=np.random.rand(50)
y=np.random.rand(50)
ax1.scatter(x,y)
# 第二个平行直线图
x=np.linspace(0,9,10)
y=x
for i in range(7):
    ax2.plot(x,y+i)
# 第三个条形图
x=np.arange(5)
y1,y2,y3=np.random.randint(1,25,size=(3,5))
# print(y1,y2,y3)
ax3.bar(x,y2,width=0.2)
ax3.bar(x+0.2,y1,width=0.2)
ax3.bar(x+0.4,y3,width=0.2)
# plt.show()
# import matplotlib.patches as mpathes
# 第四个圆形
for i in range(7):
    xy=np.random.normal(size=2)
    cir=plt.Circle(xy,0.5)
    ax4.add_patch(cir)
ax4.axis('equal')
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值