一、当我们用Python matplot时作图时,一些数据需要以百分比显示,以更方便地对比模型的性能提升百分比。
二、借助matplotlib.ticker.FuncFormatter(),将坐标轴格式化。
例子:
# encoding=utf-8
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
plt.rcParams['font.family'] = ['Times New Roman']
plt.rcParams.update({'font.size': 8})
x = range(11)
y = range(11)
plt.plot(x, y)
plt.show()
图形显示如下:
现在我们将横纵坐标变成百分比形式即,0%,20%,40%....代码如下:
# encoding=utf-8
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
plt.rcParams['font.family'] = ['Times New Roman']
plt.rcParams.update({'font.size': 8