可视化——matploblib常见api(三)

可视化——matplotlib常用api(一)

可视化——matploblib常见api(二)

fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(0, 5, .01)
y = np.cos(2*np.pi*t)
line, = ax.plot(t, y, lw=2)

Annotating text



import matplotlib.pyplot as plt
import numpy as np

def main():
    fig = plt.figure()
    ax = fig.add_subplot(111)

    t = np.arange(0, 5, .01)    
    y = np.cos(2*np.pi*t)

    line, = ax.plot(t, y, lw=2)

    ax.set_ylim([-2+.2, 2-.2])
    ax.annotate('local max', xy=(3, 0), xytext=(3.5, 1.5), arrowprops=dict(facecolor='k', shrink=.05))
    plt.show()
if __name__ == '__main__':
    main()

画圆(矩形、椭圆)

from matploblib.patches import Cicle, Ellipse
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ell1 = Ellipse(xy=(.0, .0), width=4, height=8, angle=30, facecolor='y', alpha=.3)
cir1 = Circle(xy=(.0, .0), radius=2, alpha=.4)
                    # alpha的设置很重要,否则画出来的图会很丑
ax.add_patch(ell1)
ax.add_patch(cir1)
x, y = 0, 0
ax.plot(x, y, 'ro')
ax.axis('scaled')
plt.show()

你可能感兴趣的:(可视化——matploblib常见api(三))