I use matplotlib to create a figure with 4 sub-plots in it.
I would like to split one of my title of a subplot, such that each line would be in the centered with respect to subplot.
I tried
import matplotlib.pylab as plt fig = plt.figure(num=0,figsize=(8.27, 11.69), dpi=300) ax = fig.add_subplot(2, 2, 1) ax.set_title(r'Normalized occupied \\ Neighbors')
and what i get is that Neighbors
is indent to left side.
How could i correct this?
In order to split the figure you should give 3-digit integer as a parameter to subplot() . The integers describe the position of subplots: first digit is the number of rows, the second is the number of columns, and the third is the index of the subplot.
The number p increases from 1 up to m x n , and the plots are placed from left to right, and top to bottom. In this case, when you do subplot(1,2,1); or subplot(121); , you would like to have one row and two columns worth of figures. The last number, p=1 means that you wish to place the plot in the left most column.
We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots. They are the fractions of axis width and height, respectively.
I get the correct alignment when I format the string this way:
import matplotlib.pylab as plt fig = plt.figure()#num=0,figsize=(8.27, 11.69), dpi=300) ax = fig.add_subplot(2, 2, 1) ax.set_title('Normalized occupied \n Neighbors') plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With