【发布时间】:2020-11-05 22:00:56
【问题描述】:
我正在尝试使用代码生成以下情节:
import numpy as np
import matplotlib.pyplot as plt
from mpltools import annotation
import matplotlib.ticker as ticker
h = np.array([1.44, 0.72, 0.36, 0.18])
m2_velocity_2 = np.array([0.088373, 0.0440217, 0.0149557, 0.00429101])
m2_pressure_2 = np.array([1.62808, 0.741043, 0.244384, 0.069385])
fig = plt.figure(figsize=(10, 5))
ax1 = plt.subplot(121)
ax1.loglog(h, m2_velocity_2, '-*', label='weight = 2')
annotation.slope_marker((0.4, 0.012), (2, 1), ax=ax1)
ax1.xaxis.set_major_locator(ticker.MaxNLocator(nbins=3))
ax1.set_title("Velocity")
ax1.set_xlabel("Average particle spacing")
ax1.set_ylabel("RMS error")
ax1.grid()
ax2 = plt.subplot(122)
ax2.loglog(h, m2_pressure_2, '-*', label='weight = 2')
annotation.slope_marker((0.4, 0.20), (2, 1), ax=ax2)
ax2.set_title("Pressure")
ax2.set_xlabel("Average particle spacing")
ax2.set_ylabel("RMS error")
ax2.grid()
fig.tight_layout()
plt.show()
这在轴上产生了非常紧密的刻度。我已经尝试过this 和this 的方法,但它似乎并没有清理轴。附上上面代码生成的图:
有什么建议吗?
【问题讨论】:
-
rotation=45代替复杂的手动代码/标签设置怎么样? -
@Mr.T 我正在尝试解决我的审稿人所说的问题,而不会造成更多麻烦,所以可能会再保存一次......
标签: python python-3.x matplotlib