
25) for i in range(rows*columns): exec (f"plt.subplot(grid”).
#SUBPLOT IDEAS CODE#
For example, if you want to create Figure 6 (two rows and 4 columns) with gridspec, you can use this code import matplotlib.pyplot as plt fig = plt.figure(figsize=(16, 6)) rows = 2 columns = 4 grid = plt.GridSpec(rows, columns, wspace =. Create simple axes in a figure with gridspecĪs I mentioned before, besides using subplot to create some axes in a figure, you can also use gridspec. After that, create the subplot using the same procedure with the previous code, but place it in looping syntax. , 248 for i in range(len(coord)): plt.subplot(coord) plt.annotate('subplot ' + str(coord), xy = (0.5, 0.5), va = 'center', ha = 'center')īecause you want to create 8 axes (2 rows and 4 columns), so you need to make an array from 241 to 248. , 248 for i in range(1, 9): # in python, 9 is not included row = 2 column = 4 coord.append(str(row)+str(column)+str(i)) # create subplot 241, 242, 243. You can reproduce Figure 6 using this code fig = plt.figure(figsize=(16, 6)) coord = # create coord array from 241, 242, 243. Create a simple subplot using looping in Matplotlib (Image by Author). You can use this code to generate it fig = plt.figure(figsize=(12, 4)) coord1 = 121 coord2 = 122 plt.subplot(coord1) plt.annotate('subplot ' + str(coord1), xy = (0.5, 0.5), va = 'center', ha = 'center') plt.subplot(coord2) plt.annotate('subplot ' + str(coord2), xy = (0.5, 0.5), va = 'center', ha = 'center')įigure 6. Next step is creating two horizontal axes in a figure, as shown in Figure 4. You also can generate Figure 3 without subplot syntax because you only generate one axes in a figure. Because you only have one row and one column (it means you only have one cell), your axes are the main figure. coord 111 means, you generate a figure that consists of one row, one column, and you insert the subplot in the first sequence axes. It consists of three numbers representing the number of rows, columns, and the axes’ sequence. The variable coord in the code above is 111.
#SUBPLOT IDEAS GENERATOR#
Masterpiece Generator refers to a set of text generator tools created by Aardgo. We automatically create a plot, title and a cover for your novel or film.

Give us some keywords to play with or let us prompt some ideas at random. One of the important things to understand the subplot in Matplotlib is defining the coordinate of the axes. Choose a theme from our selection of plot generators. You can generate Figure 3 using the following code import matplotlib.pyplot as plt fig = plt.figure() coord = 111 plt.subplot(coord) plt.annotate('subplot ' + str(coord), xy = (0.5, 0.5), va = 'center', ha = 'center') A simple subplot in Matplotlib (Image by Author).
