# Turn ticks on for the last ax in each column, wherever it lands # Delete any unused axes from the figure, so that they don't show # Choose the traversal you'd like: 'F' is col-wise, 'C' is row-wiseĪxes = axes.flatten(order=('C' if row_wise else 'F')) If there's only one plot, it's just an Axes obj # Choose your share X and share Y parameters as you wish: Nrow, ncol = choose_subplot_dimensions(k) # I've chosen to have a maximum of 3 columnsĭef generate_subplots(k, row_wise=False): You can change the stylistic choices to match your preferences. The two functions I define are the follows. I wrote a little utility function to stop having to think about it. I generate an arbitrary number of subplots all the time (sometimes the data leads to 3 subplots, sometimes 13, etc). import numpy as npį, axs = plt.subplots(n/2, 2, sharex=True)į, axs = plt.subplots(n/2+1, 2, sharex=True)Īxs.plot(x, y, '-', label='plot '+str(i+1)) In this example I want to force xtick labels when i=3. The number of subplots can be quite large (>20). I can't find a way of doing that and using the sharex=True option at the same time. If the number of required plots is odd, then I would like to remove the last panel and force the tick labels on the panel right above it. I'm trying to create a plotting function that takes as input the number of required plots and plots them using pylab.subplots and the sharex=True option.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |