when using boxplot with matplotlib , I wouldlike to have the x ticks to adapt to the figure size, so that the x-axis is not completely unreadable
Example
import numpy as np
import matplotlib.pyplot as plt
x = np.random.uniform(size = (20, 50))
fig, ax = plt.subplots()
ax.boxplot(x, positions=np.arange(1, x.shape[1]+1))
which gives me
I expected the tick labels to adapt as for a regular plot, but apparently not. Any workarounds?
2
Boxplot uses a FixedLocator
to determine the tick locations, change it to AutoLocator
:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoLocator, ScalarFormatter
x = np.random.uniform(size = (20, 50))
fig, ax = plt.subplots()
ax.boxplot(x, positions=np.arange(1, x.shape[1]+1))
ax.xaxis.set_major_locator(AutoLocator())
ax.xaxis.set_major_formatter(ScalarFormatter())