If you want to use mpl_toolkits and make your hands dirty, this answer would be a good read. This answer for using the subplot parameters to achieve a certain aspect. If the image does not have equal limits (is not square), one still needs to divide by the aspect of the image: asp = np.diff(ax2.get_xlim()) / np.diff(ax2.get_ylim())Īsp /= np.abs(np.diff(ax1.get_xlim()) / np.diff(ax1.get_ylim())) Or you may set the aspect of the line plot depending on its axis limits such that it gets the same size as the image (in case the image has equal x and y sizes) asp = np.diff(ax2.get_xlim()) / np.diff(ax2.get_ylim())Īsp = np.diff(ax2.get_xlim()) / np.diff(ax2.get_ylim()) You may use automatic aspect on the image ax.imshow(z, aspect="auto") It's not perfectly clear what your desired outcome is. ![]() For more advanced use cases you can use GridSpec for a more general subplot layout or Figure. import matplotlib.pyplot as plt import idspec as gridspec plt.figure(figsize (4,4)) gs1 gridspec.GridSpec(4, 4) gs1.update(wspace0.025, hspace0.05) set the spacing between axes. I am using Python 2.7 and matplotlib 2.0.0 Answers pyplot.subplots creates a figure and a grid of subplots with a single call, while providing reasonable control over how the individual plots are created. You can use gridspec to control the spacing between axes. Is there a way to make imshow and a scatter plot appear the same size in a figure without manually changing the axes sizes? I have also tried to adjust the subplot sizes manually by using: fig = plt.figure()īy trial and error I can get the two subplots to the correct size, though any change in the overall figure size will mean that the subplots will no longer be the same size. I have tried using gridspec as shown in this answer: fig=plt.figure()īut this gives the same result. By default, matplotlib creates a figure of size 10 x 8 inches or its corresponding ratio. How can I get the two sublpots to have the same height? (and width I suppose) ![]() Small example code is shown below: import matplotlib.pyplot as plt When trying this, the image appears smaller than the scatter plot. However, users may need to specify their figures in other units. While subplot positions the plots in a regular grid, axes allows free. I am trying to plot an image (using matplotlib.imshow) and a scatter plot within the same figure. The native figure size unit in Matplotlib is inches, deriving from print industry standards. We can have more control over the display using figure, subplot, and axes explicitly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |