matplotlib 绘图库

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data = np.arange(10)
data
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
plt.plot(data)
[<matplotlib.lines.Line2D at 0x226505a9978>]

在这里插入图片描述

图片与子图

使用plt.figure生成一个新的图片
fig = plt.figure()
<Figure size 432x288 with 0 Axes>

add_subplot创建一个或多个子图(subplot)

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)

plt.plot(np.random.randn(50).cumsum(),'k--')

_ = ax1.hist(np.random.randn(100),bins=20,color='k',alpha=0.3)
ax2.scatter(np.arange(30),np.arange(30)+3*np.random.randn(30))
<matplotlib.collections.PathCollection at 0x22652533c50>

在这里插入图片描述

s = pd.Series(np.random.randn(10),index=np.arange(0,100,10))
s
0    -0.216889
10   -0.926422
20   -1.578404
30    1.260680
40    0.765321
50    1.575562
60   -0.226129
70   -1.545994
80    1.461791
90    0.216152
dtype: float64
s.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x22652df9518>

在这里插入图片描述

df = pd.DataFrame(np.random.randn(10,4).cumsum(0),
                                 index=np.arange(0,100,10),
                                 columns=['A','B','C','D'])
df
ABCD
00.148623-0.4647320.170983-1.931102
102.051717-0.5474952.022106-1.521699
202.851331-1.7038500.804570-1.245837
304.236059-0.8078663.380667-0.467652
405.586521-1.8197893.505844-0.112501
504.943688-0.5780194.009679-1.821747
605.507788-1.1726904.345803-4.397258
704.5984290.1470673.977140-4.439640
804.662817-0.2756866.488330-2.747436
902.2052900.1455586.516990-3.706320
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x22652e85d68>

在这里插入图片描述

# 柱状图

s.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x22652efc390>

在这里插入图片描述

s.plot(kind='barh')
<matplotlib.axes._subplots.AxesSubplot at 0x22652f3ae80>

在这里插入图片描述

df.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x22652fc05c0>

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(19680801)


fig, ax = plt.subplots()
ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='blue')
ax.grid()

fig.text(0.95, 0.05, 'Property of MPL',
         fontsize=50, color='gray',
         ha='right', va='bottom', alpha=0.5)

plt.show()

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值