I'd therefore recommend you use () since it is more concise and easy to use. The code above can be condensed with a loop, but it is still considerably more tedious to use. a certain amount of padding around the outside of the subplots and spacing between subplots. Or you can also use built-in method of fig: ax1 = fig.add_subplot(231) AxesSubplot object at 0x7f5893019b50>, ax2) plt.subplots (nrows2) The rest is basically adjusting the code for the new situation. You need to use a GridSpec instead of subplotsadjust(), that way tightlayout() will know that you want zero-space and it keep it that way. # now you have to create each subplot individually So, what you need instead is only two subplots, which you may directly unpack. This means it will require several lines of code to achieve the same result as () did in a single line of code above: # first you have to make the figure In contrast, () creates only a single subplot axes at a specified grid position. For example, the code below will return both fig which is the figure object, and axes which is a 2x3 array of axes objects which allows you to easily access each subplot: fig, axes = plt.subplots(nrows=2, ncols=3) The subplot spacing is configured so that they run. For more advanced use cases you can use GridSpec for a more general subplot layout or Figure.addsubplot for adding subplots at arbitrary locations within the figure. That means you can use this single function to create a figure with several subplots with only one line of code. This code generates a figure of 10 subplots depicting the graph of sin(npi x) for n0,1,cdots, 9. 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. import matplotlib.pyplot as plt import numpy as np plot 1: x np.array(0, 1, 2, 3) y np.array(3, 8, 1, 10) plt.subplot(1, 2, 1) plt.plot(x,y) plot 2: x np. This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |