将行添加plt.yscale('log')
到我的简单绘图脚本后
import numpy as np
residuals = np.loadtxt('res_jacobi.txt', skiprows=1)
import matplotlib.pyplot as plt
fig = plt.figure()
steps = np.arange(0, len(residuals), 1)
plt.plot(steps, residuals, label='$S$')
plt.xlabel("Step",fontsize=20)
plt.ylabel("$S$",fontsize=20)
plt.ylim(0.95 * min(residuals), 1.05 * max(residuals))
plt.yscale('log')
plt.savefig('jacobi-res.pdf', bbox_inches='tight', transparent=True)
y标签消失。
我敢肯定有一个简单的解决办法,但是搜索并没有解决这个问题。任何帮助将非常感激。
的正常行为matplotlib
是仅在对数缩放中标记主要刻度线,它们甚至是数量级,例如{0.1, 1.0}
。您的价值观介于两者之间。你可以:
plt.gca().set_ylim(0.1, 1.0)
plt.gca().yaxis.set_minor_formatter(FormatStrFormatter("%.2f"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句