使用 matplotlib 画图的保存方法有两种

使用 matplotlib 画图的保存方法有两种

方法一

使用 plt.savefig( )
使用 matplotlib 画图的保存方法有两种_第1张图片
填入保存图片的位置,一句简单的语句就可以保存,直接KO掉截图这一low操作。

方法二

使用%matplotlib qt5 #弹出窗口,可以放大、缩小

注意:代码基于jupyter notebook 实现

import matplotlib.pyplot as plt
%matplotlib qt5   #弹出窗口,可以放大、缩小
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei'] # 用来显示正常的中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号

x = np.linspace(0.05,10,1000)   
y = np.sin(x)

plt.plot(x,y)
ax = plt.gca()
ax.spines['right'].set_color('red')
ax.spines['left'].set_color('pink')
ax.spines['top'].set_color('yellow')
ax.spines['bottom'].set_color('green')

使用 matplotlib 画图的保存方法有两种_第2张图片

使用该语句,弹出画图窗口,可以直接点击保存按钮即可。

你可能感兴趣的:(使用 matplotlib 画图的保存方法有两种)