Python应用matplotlib绘图简介

现在通过numpy和matplotlib在Python上实现科学计算和绘图,而且和matlab极为想象(效率差点,关键是方便简单)

1. 最简单的绘图实例

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 10, 0.2)
y = np.sin(x)

plt.plot(x, y)
plt.show()

Python应用matplotlib绘图简介_第1张图片

2. 一个负责的例子

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure

x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 3.0)

y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

figure, ax1 = plt.subplots(1,1)
# plt.subplots_adjust(left=0.14, bottom=0.1)
# ax1 = figure.add_axes([0.14, 0.35, 0.77, 0.6 ])
ax1.grid(True)
ax1.plot(x1, y1, 'yo-', label="Test1")
ax1.plot(x2, y2, 'r.-', label='Test2')

plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)

plt.show()

Python应用matplotlib绘图简介_第2张图片

3. 其它

更多实例请参考:http://matplotlib.org/users/screenshots.html

你可能感兴趣的:(python,绘图,matplotlib,科学计算,numpy)