I am trying to produce the following plot using the code:
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()
which produced a very tight chunk of ticks in the axis. I have tried methods from this and this but it doesn't seem to clean up the axis. Attached is the graph generated from the code above:
Any suggestions?