![]() ![]() I'm explicitly selecting that there will be 2 sub plots in my figure, and that the figure will be chosen_value tall and each subplot will be about half that size wide, and that the subplots will have an aspect ratio of 1 (i.e., they will both be square). ![]() Python3 import matplotlib.pyplot as plt x 1, 2, 3, 4, 5 y 9, 8, 7, 6, 5 fig, ax plt. #MATPLOTLIB SUBPLOT SIZE CODE#Here's some code I use: fig, axis_array = plt.subplots(1, 2, figsize=(chosen_value, 1.05 * chosen_value / 2), If we want to change the font size of the axis labels, we can use the parameter fontsize and set it your desired number. If you change your code to: fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6)) The problem is that the plot region height is too large and this is leaving empty place in the image. Since this subplot will overlap the first, the plot (and its axes) previously created, will be removed plt. The solution proposed by worked like a charm for me, but for completeness, I'd like to mention a pretty simple workaround I was suggested to apply (credit to Zhang) before my question was marked as an exact duplicate of this one: import matplotlib.pyplot as plt plot a line, implicitly creating a subplot (111) plt.plot( 1, 2, 3) now create a subplot which represents the top plot of a grid with 2 rows and 1 column. ![]() I had the same problem and asked a very similar question in SO. If you want to use mpl_toolkits and make your hands dirty, this answer would be a good read. To change the size of subplots in Matplotlib, use the plt.subplots() method with the figsize parameter (e.g., figsize(8,6) ) to specify one size for all. 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |