繁体   English   中英

Python & Matplotlib:将 x 轴置于中心,但刻度和标签不跟随 x 轴

[英]Python & Matplotlib: put x-axis in centre but tick and label is not followed to the x-axis

Matplotlib ,我想让 x 轴始终通过 (0, 0)。 接下来是一个小代码。 如您所见,x 轴调整到图形的中间。 我想要的是在 (0, 1.5) 处显示的 x 轴总是在 (0,0) 处。

import pandas as pd
import matplotlib.pyplot as plt  

fig = plt.figure()
ax = fig.add_subplot(111)

x=[0,2.7,5.4]
y=[0,3.0,0]
ax.plot(x, y)

ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
#  ax.spines['bottom'].set_color('none')

plt.gca().invert_yaxis()
plt.show()

在此处输入图片说明

文档中,设置脊椎的位置时使用'zero'

ax.spines['bottom'].set_position('zero')

输出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM