matplotlib简单画图

matplotlib简单画图


一、使用步骤

代码如下:

import numpy as np
from pandas import DataFrame
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(10, 8))  # 建立一个大小为10*8的画板
ax1 = fig.add_subplot(3, 3, 1)  # 在画板上添加3*3个画布,位置是第1个
ax2 = fig.add_subplot(3, 3, 2)
ax3 = fig.add_subplot(3, 3, 3)
ax4 = fig.add_subplot(3, 3, 4)
ax5 = fig.add_subplot(3, 3, 5)
ax6 = fig.add_subplot(3, 3, 6)
ax7 = fig.add_subplot(3, 3, 7)
ax8 = fig.add_subplot(3, 3, 8)
ax9 = fig.add_subplot(3, 3, 9)

ax1.plot(np.random.randn(10))
ax2.scatter(np.random.randn(10), np.arange(10), color='r')  # 作散点图
ax3.hist(np.random.randn(20), bins=10, alpha=0.3)  # 作直方图
ax4.bar(np.arange(10), np.random.randn(10))  # 做柱形图
ax5.pie(np.random.randint(1, 15, 5), explode=[0, 0, 0.2, 0, 0])  # 作饼形图

x = np.arange(10)
y = np.random.randn(10)
ax6.plot(x, y, color='green')
ax6.bar(x, y, color='k')

data = DataFrame(np.random.randn(1000, 10),columns=['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'])
data2 = DataFrame(np.random.randint(0, 20, (10, 2)), columns=['a', 'b'])

data.plot(x='one', y='two', kind='scatter', ax=ax7)  # 针对DataFrame的一些作图
data2.plot(x='a', y='b', kind='bar', ax=ax8, color='red', legend=False)
data2.plot(x='a', y='b', kind='barh', color='m', ax=ax9)

plt.show()

二、效果图

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大虾飞哥哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值