Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to set a single main title above all the subplots with pyplot

import matplotlib.pyplot as plt
import numpy as np

# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, axarr = plt.subplots(2, 2)
fig.suptitle("This Main Title is Nicely Formatted", fontsize=16)

axarr[0, 0].plot(x, y)
axarr[0, 0].set_title('Axis [0,0] Subtitle')
axarr[0, 1].scatter(x, y)
axarr[0, 1].set_title('Axis [0,1] Subtitle')
axarr[1, 0].plot(x, y ** 2)
axarr[1, 0].set_title('Axis [1,0] Subtitle')
axarr[1, 1].scatter(x, y ** 2)
axarr[1, 1].set_title('Axis [1,1] Subtitle')

# Fine-tune figure;
# hide x ticks for top plots and y ticks for right plots

plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)


# Tight layout often produces nice results
# but requires the title to be spaced accordingly

fig.tight_layout()
fig.subplots_adjust(top=0.88)

plt.show()


Comment

PREVIOUS NEXT
Code Example
Python :: how to add subtitle to plot in python 
Python :: how to make a dice program in python 
Python :: check type of variable in python 
Python :: python print function 
Python :: python all permutations of a string 
Python :: How can write event for textbox in tkinter 
Python :: range of y & x in scatter 
Python :: Got AttributeError when attempting to get a value for field `name` on serializer 
Python :: python - count number of occurence in a column 
Python :: django model remove duplicates 
Python :: Splitting strings in Python without split() 
Python :: Replace all the empty rows in the column with the value that you have identified 
Python :: read an excel file 
Python :: how to convert integer to binary string python 
Python :: regex find email address in string python 
Python :: how to find avrage python 
Python :: soup.find_all attr 
Python :: pytest temp directory 
Python :: how to redirect user in flask response python 
Python :: python returned non-zero exit status 1. 
Python :: list_display django foreign key 
Python :: matplotlib legend number columns 
Python :: list pop python 
Python :: length of a string python 
Python :: python synonym library 
Python :: open and write in a file in python 
Python :: R sample() funciton in python 
Python :: python concatenation 
Python :: calculate mean of column pandas 
Python :: Neuraal Netwerk python text 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =