I'd like to recursively plot a number of lines with errorbars on one figure. I have a lot of plots to make that all have the same x-axis limits, axes labels, and figure size, so I'm trying to re-use the same figure by just removing all the data on the plot and re-plotting, however I cannot seem to remove the errorbars.
Here's an example of what I have tried (where xs, ys, and yerrs are the x values, y values, and y errors):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 6), constrained_layout=True)
ax.set_xlim(0, 10)
ax.set_xlabel("x")
ax.set_ylabel("y")
for i in range(number_of_plots):
for j in range(lines_per_plot):
ax.errorbar(xs[i, j], ys[i, j], yerr=yerrs[i, j])
ax.relim()
ax.autoscale(axis="y")
fig.savefig("%s.pdf" % i)
for line in ax.get_lines():
line.remove()
This only removes the main data, but I would like to also remove the errorbars. Any help is appreciated.