Make_axes_locatable returns an instance of the AxesLocator class,ĭerived from the Locator. Make_axes_locatable, which can be useful. The axes_divider module provides a helper function The example from the linked page also works without using subplots: import matplotlib.pyplot as plt from mpltoolkits.axesgrid1 import makeaxeslocatable import numpy as np plt.figure() ax plt.gca() im ax.imshow(np.arange(100).reshape((10,10))) create an axes on the right side of ax. You can change the locations and labels of the ticks on either axis with the set_ticks and set_ticklabels methods as in the example above.Īs for what the make_axes_locatable function does, from the matplotlib site about the AxesGrid toolkit: You can do this easily with a matplotlib AxisDivider. # Manually set ticklabels (not ticklocations, they remain unchanged)Īx4.set_yticklabels() # and the format of the ticklabels with kwarg `format`Ĭbar3 = plt.colorbar(im3, cax=cax3, ticks=MultipleLocator(0.2), format="%.2f")Īx3.set_yticks() # Tick locations can be set with the kwarg `ticks` # Append axes to the right of ax3, with 20% width of ax3Ĭax3 = divider3.append_axes("right", size="20%", pad=0.05) # Create divider for existing axes instance # Display image, `aspect='auto'` makes it fill the whole `axes` (ax3) # Set locations of ticks on x-axis (at every multiple of 2)Īx2.t_major_locator(MultipleLocator(2)) can also be a two-tuple specifying the () indices (1-based, and including ) of the subplot, e.g., fig.addsubplot (3, makes a subplot that spans the upper 2/3 of the figure. starts at 1 in the upper left corner and increases to the right. # Set locations of ticks on y-axis (at every multiple of 0.25)Īx2.t_major_locator(MultipleLocator(0.25)) The subplot will take the position on a grid with nrows rows and ncols columns. Tot2 = np.repeat(s,width).reshape(len(s), width)įig, (ax1, ax2, ax3, ax4) = plt.subplots(1,4)įig.suptitle('Title of figure', fontsize=20) Tot = np.repeat(s,width).reshape(len(s), width) The following code first displays what I need as a subplot and the second one shows all I can do, which is not sufficient. I use this for displaying the data of the "regular" plots above as a colormap (by scaling the input-array i to for 2D and calling imshow() with it). lorbar() retrieve an existing colorbar, that you can do following (and upvoting :)) what I wrote here: How to retrieve colorbar instance from figure in matplotlib then: cb.remove() plt. This, however, seems to be absolutely useless for the subplotting. holding the colorbar in a value at the moment of creation, as shown in other answers e.g. I can format the imshow-images to proper plots itself, because every single one of them needs its own colorbar, a modified axis and the other axis removed. Two of them are usual line-plots, two of them imshow-images. I want to have a figure consisting of, let's say, four subplots.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |