设置位置(“中心”)和设置位置(“零”)在以下方面有什么区别斧刺

2024-04-19 19:43:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一个像this这样的情节。你知道吗

我研究了来自matplotlib的例子。你知道吗

我所知道的是

  1. 左脊柱在笛卡尔坐标平面上起y轴的作用。

  2. 底部脊柱在笛卡尔坐标平面上可以起到x轴的作用。

  3. set_position()可以移动脊椎。

我的问题是把脊柱(比如说“左”)放在“中心”和“零”之间有什么区别。你知道吗

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2 * np.sin(x)

ax = fig.add_subplot(2, 2, 1)
ax.set_title('centered spines')
ax.plot(x, y)
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

ax = fig.add_subplot(2, 2, 2)
ax.set_title('zeroed spines')
ax.plot(x, y)
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
plt.show()

Tags: nonetruesmartnppositionpltaxleft