gpt4 book ai didi

python - 将 Y 轴移动到 matplotlib 中的另一个位置

转载 作者:行者123 更新时间:2023-12-01 04:36:57 24 4
gpt4 key购买 nike

我有以下情节:

Normal Plot

我想用刻度线和所有东西将 y 轴移动到 x = 0,我该怎么做?

最佳答案

给你

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2*np.sin(x)

ax = fig.add_subplot(111)
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('bottom')
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')

更多示例:http://matplotlib.org/examples/pylab_examples/spine_placement_demo.html

关于python - 将 Y 轴移动到 matplotlib 中的另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31547449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com