I have a series of box plots I am trying to make, each of which has a different range. I tried setting ylim by determining the max and min of each separate series. Howe
You could inspect the whiskers (maplotlib.lines.Line2D objects) returned by df.boxplot(). For example, if you call
bp = df.boxplot(ax=ax)
then bp['whiskers'] will be a list of Line2D objects. You can find the y-values for each line using
yval = np.concatenate([line.get_ydata() for line in bp['whiskers']])
and then use yval.min() and yval.max() to determine the desired y-limits.
For example,
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df = pd.DataFrame(np.random.poisson(5, size=(100, 5)))
bp = df.boxplot(ax=ax)
yval = np.concatenate([line.get_ydata() for line in bp['whiskers']])
eps = 1.0
ymin, ymax = yval.min()-eps, yval.max()+eps
ax.set_ylim([ymin,ymax])
plt.show()
yields