[matplotlib] Set the coordinate axis scale to the inward direction when drawing

Background: I recently wrote a small paper, and the journal required the scale of the axis of the chart to be inward. After consulting the data, I made some new discoveries.

import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = x

plt.figure()
# 坐标轴的刻度设置向内(in)或向外(out)
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
# 画图
plt.plot(x, y, '-o')
# 设置背景网格线为虚线
plt.grid(linestyle="--") 
# 设置坐标轴标签                  
plt.xlabel("时间/s", fontsize=7.5,fontproperties="SimSun")
plt.ylabel("角度/(°)", fontsize=7.5,fontproperties="SimSun")
# 显示图像
plt.show()

insert image description here

Points to note:
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
is placed before plt.plo. Moreover, plt.grid, plt.xlabel, and plt.ylabel should be placed at the end, otherwise, there will be interference, and the inward direction cannot be set, and the outward direction is still set.

Guess you like

Origin blog.csdn.net/qq_41821678/article/details/105803150#comments_27303833