修复图中轴值的范围
fix the range of axis values in plot
我正在绘制准确率和损失数据。
我得到以下图代表 0 之后的 3 个位置,例如 0.XXX 我的目标是只显示一个,例如 0.X
我该如何解决这个问题
acc = history.history['accuracy']
acc_val = history.history['val_accuracy']
epochs = range(len(acc))
plt.title('Training and Validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('accuracy')
plt.legend()
plt.show()
accuracy figure
试试下面的方法:
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
acc = history.history['accuracy']
fig, ax = plt.subplots()
plt.plot([i for i in range(len(acc))], acc)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.show()
但是您可能会看到多个具有相同值的刻度。或者或另外,您可以使用以下内容将刻度限制为您想要显示的内容:
ax.set_yticks([0.8, 0.9, 1.0])
我正在绘制准确率和损失数据。 我得到以下图代表 0 之后的 3 个位置,例如 0.XXX 我的目标是只显示一个,例如 0.X
我该如何解决这个问题
acc = history.history['accuracy']
acc_val = history.history['val_accuracy']
epochs = range(len(acc))
plt.title('Training and Validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('accuracy')
plt.legend()
plt.show()
accuracy figure
试试下面的方法:
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
acc = history.history['accuracy']
fig, ax = plt.subplots()
plt.plot([i for i in range(len(acc))], acc)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.show()
但是您可能会看到多个具有相同值的刻度。或者或另外,您可以使用以下内容将刻度限制为您想要显示的内容:
ax.set_yticks([0.8, 0.9, 1.0])