top of page

[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 All

[Python] Output pandas.DataFrame as json

Summary Data analysis is performed using python. The analysis itself is performed using pandas, and the final results are stored in pandas.DataFrame format. I want to output this result to a file in j

[Python] Conditionally fitting

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 cases where you want to condition the fitting parameters. For

Comments


Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page