对数 y 轴使刻度标签消失
Logarithmic y axis makes tick labels disappear
将 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 标签消失。
我确定有一个简单的修复方法,但搜索没有找到。任何帮助将不胜感激。
semilogy
适合我。
变化:
plt.plot(steps, residuals, label='$S$')
进入:
plt.semilogy(steps, residuals, label='$S$')
删除plt.yscale('log')
matplotlib
的正常行为是仅标记对数标度中的主要刻度线 --- 这是偶数个数量级,例如{0.1, 1.0}
。你的价值观介于两者之间。您可以:
- 将坐标轴重新缩放到更大的范围,
plt.gca().set_ylim(0.1, 1.0)
- 手动标记刻度线,
plt.gca().yaxis.set_minor_formatter(FormatStrFormatter("%.2f"))
将 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 标签消失。
我确定有一个简单的修复方法,但搜索没有找到。任何帮助将不胜感激。
semilogy
适合我。
变化:
plt.plot(steps, residuals, label='$S$')
进入:
plt.semilogy(steps, residuals, label='$S$')
删除plt.yscale('log')
matplotlib
的正常行为是仅标记对数标度中的主要刻度线 --- 这是偶数个数量级,例如{0.1, 1.0}
。你的价值观介于两者之间。您可以:
- 将坐标轴重新缩放到更大的范围,
plt.gca().set_ylim(0.1, 1.0)
- 手动标记刻度线,
plt.gca().yaxis.set_minor_formatter(FormatStrFormatter("%.2f"))