subplot - Multiplot with matplotlib without knowing the number of plots before running -
i have problem, matplotlib subplot confuses me. not know number of subplots want plot beforehand, know want them in 2 rows. cannot use
plt.subplot(212) because don't know number should provide.
it should this:

right plot plots folder , put them illustrator, there has better way matplotlib. can provide code if unclear somewhere.
my understanding know number of plots @ runtime , hence struggling shorthand syntax, e.g.:
plt.subplot(121) thankfully, save having awkward math figure out number programatically, there interface allows use form:
plt.subplot(n_cols, n_rows, plot_num) so in case, given want n plots, can do:
n_plots = 5 # (or many programatically figure out need) n_cols = 2 n_rows = (n_plots + 1) // n_cols plot_num in range(n_plots): ax = plt.subplot(n_cols, n_rows, plot_num) # ... plotting alternatively, there more pythonic interface may wish aware of:
fig, subplots = plt.subplots(n_cols, n_rows) ax in subplots: # ... plotting (notice subplots() not plain subplot()). although must admit, have never used latter interface.
hth
Comments
Post a Comment