[python] Adjust the distance between the axis of the graph and the axis label
Overview
When drawing a graph with matplotlib, you may want to adjust the distance between the axis and the axis label.
Personally, I feel that the axis and axis label are too close, especially in the seaborn heatmap.
Here's how to deal with such cases.
Method
You can adjust the distance between the axes by specifying the labelpad as an argument of xlabel ().
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x=np.random.rand(5, 5)
fig, ax=plt.subplots()
sns.heatmap(x)
ax.set_xlabel('x label', fontsize=14, labelpad=20)
ax.set_ylabel('y label', fontsize=14, labelpad=20)
plt.show()
A comparison of labelpad = 0 and labelpad = 20 is shown in the figure below.
Recent Posts
See AllSummary Data analysis is performed using python. The analysis itself is performed using pandas, and the final results are stored in...
Phenomenon I get a title error when trying to import firestore with raspberry pi. from from firebase_admin import firestore ImportError:...
Overview If you want to do fitting, you can do it with scipy.optimize.leastsq etc. in python. However, when doing fitting, there are many...
Comments