@File : matplotlib_examples.py
@Software: PyCharm
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
“”"
基本使用
“”"
x = np.linspace(-5, 5, 100)
y1 = 2 * x +5
y2 = x ** 2
定义一个图像窗口,并画出图像
plt.figure(num=1, figsize=(8,5))
plt.plot(x, y1, label = ‘linear’, color = ‘red’, linestyle=‘–’)
plt.plot(x, y2, label = ‘square’, color = ‘blue’)
调整坐标轴名字及其间隔
plt.ylim(-5, 20)
plt.xlim(-5, 5)
plt.xlabel(‘x’)
plt.ylabel(‘y’)
设置坐标轴刻度及对应名
new_ticks = np.linspace(-5, 4, 10)
print(new_ticks)
plt.xticks(new_ticks)
plt.yticks([-3, -1, 3, 10, 18],[r’ r e a l l y b a d really\ bad really bad’, r’