matlablib 作图

Example1: 使用matlablib做图

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5, 5, 100)
y1 = np.sin(x)
y2 = np.cos(x)

plt.figure(num=3, figsize=(8, 5))

plt.plot(x, y1)
plt.plot(x, y2, color='blue', linewidth=5.0, linestyle='--')

plt.xlim((-5, 5))
plt.ylim((-2, 2))

plt.xlabel('x axis')
plt.ylabel('y axis')

my_x_ticks = np.arange(-5, 5, 1.5)
my_y_ticks = np.arange(-2, 2, 1.5)
plt.xticks(my_x_ticks)
plt.yticks(my_y_ticks)

plt.show()

Example2: 使用numpy array数据进行matlablib做图

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(1, 10, 10)
y = np.array([1,2,3,4,5,6,7,8,9,15])

plt.figure(num=3, figsize=(8, 5))

plt.plot(x, y)

plt.xlim((1, 10))
plt.ylim((1, 15))

plt.xlabel('x axis')
plt.ylabel('y axis')

my_x_ticks = np.arange(1, 10, 1)
my_y_ticks = np.arange(1, 15, 1)

plt.xticks(my_x_ticks)
plt.yticks(my_y_ticks)

plt.show()

参考
http://blog.csdn.net/xtingjie/article/details/71156743

你可能感兴趣的:(Matlab编程)