Insets and panels

    To generate “stacked” panels, simply call panel more than once. To include panels when centering spanning axis labels and super titles, pass includepanels=True to . Panels do not interfere with the tight layout algorithm and .

    1. import proplot as plot
    2. import numpy as np
    3. state = np.random.RandomState(51423)
    4. data = (state.rand(20, 20) - 0.48).cumsum(axis=1).cumsum(axis=0)
    5. data = 10 * (data - data.min()) / (data.max() - data.min())
    6. # Stacked panels with outer colorbars
    7. for cbarloc, ploc in ('rb', 'br'):
    8. fig, axs = plot.subplots(
    9. axwidth=1.8, nrows=1, ncols=2,
    10. share=0, panelpad=0.1, includepanels=True
    11. )
    12. axs.format(
    13. xlabel='xlabel', ylabel='ylabel', title='Title',
    14. suptitle='Using panels for summary statistics',
    15. )
    16. # Plot 2D dataset
    17. axs.contourf(
    18. data, cmap='glacial', extend='both',
    19. colorbar=cbarloc, colorbar_kw={'label': 'colorbar'},
    20. )
    21. # Get summary statistics and settings
    22. axis = int(ploc == 'r') # dimension along which stats are taken
    23. x1 = x2 = np.arange(20)
    24. y2 = data.std(axis=axis)
    25. if ploc == 'r':
    26. titleloc = 'center'
    27. x1, x2, y1, y2 = y1, y2, x1, x2
    28. # Panels for plotting the mean. We make two panels at once and plot data
    29. # on both panels at once by calling functions from SubplotsContainers.
    30. # More realistically, you would plot data on each panel one-by-one.
    31. space = 0
    32. width = '4em'
    33. kwargs = {'titleloc': titleloc, 'xreverse': False, 'yreverse': False}
    34. paxs = axs.panel(ploc, space=space, width=width)
    35. paxs.plot(x1, y1, color='gray7')
    36. paxs.format(title='Mean', **kwargs)
    37. # Panels for plotting the standard deviation
    38. paxs = axs.panel(ploc, space=space, width=width)
    39. paxs.plot(x2, y2, color='gray7', ls='--')
    40. paxs.format(title='Stdev', **kwargs)

    1. import proplot as plot
    2. fig, axs = plot.subplots(axwidth=1.5, nrows=2, ncols=2, share=0)
    3. # Demonstrate that complex arrangements of panels does
    4. # not mess up subplot aspect ratios or tight layout spacing
    5. axs.format(
    6. xlim=(0, 1), ylim=(0, 1),
    7. xlabel='xlabel', ylabel='ylabel',
    8. xticks=0.2, yticks=0.2,
    9. title='Title', suptitle='Complex arrangement of panels',
    10. collabels=['Column 1', 'Column 2'],
    11. abc=True, abcloc='ul', titleloc='uc', abovetop=False,
    12. for ax, side in zip(axs, 'tlbr'):

    _images/insets_panels_3_0.svg

    Inset axes

    1. import proplot as plot
    2. import numpy as np
    3. # Generate sample data
    4. N = 20
    5. state = np.random.RandomState(51423)
    6. x, y = np.arange(10), np.arange(10)
    7. data = state.rand(10, 10)
    8. # Plot sample data
    9. fig, ax = plot.subplots(axwidth=3)
    10. m = ax.pcolormesh(data, cmap='Grays', levels=N)
    11. ax.colorbar(m, loc='b', label='label')
    12. ax.format(
    13. xlabel='xlabel', ylabel='ylabel',
    14. suptitle='"Zooming in" with an inset axes'
    15. )
    16. # Create inset axes representing a "zoom-in"
    17. iax = ax.inset(
    18. [5, 5, 4, 4], transform='data', zoom=True,
    19. zoom_kw={'color': 'red3', 'lw': 2, 'ls': '--'}
    20. )
    21. iax.format(
    22. xlim=(2, 4), ylim=(2, 4), color='red7',
    23. linewidth=1.5, ticklabelweight='bold'
    24. )