One - One Code All

Blog Content

matplotlib绘图横坐标或纵坐标文本显示不全

Python   2020-03-07 15:45:23

通过 plt.subplots_adjust(bottom=0.15),来调整 图表 的上下左右, top, bottom, left, right。



https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots_adjust.html
import matplotlib.pyplot as plt
 
 
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']
 
plt.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
# Pad margins so that markers don't get clipped by the axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
plt.show()



上一篇:docker-compose up和restart的区别
下一篇:matplotlib X轴日期倾斜位置调整(双Y轴)

The minute you think of giving up, think of the reason why you held on so long.