如何删除 matplotlib 中的顶部和右侧轴? [英] How can I remove the top and right axis in matplotlib?
本文介绍了如何删除 matplotlib 中的顶部和右侧轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想拥有左轴和底轴,而不是默认的盒装"轴样式,即:
Instead of the default "boxed" axis style I want to have only the left and bottom axis, i.e.:
+------+ |
| | |
| | ---> |
| | |
+------+ +-------
这应该很容易,但我在文档中找不到必要的选项.
This should be easy, but I can't find the necessary options in the docs.
推荐答案
这是官网推荐的 Matplotlib 3 解决方案 此处:
This is the suggested Matplotlib 3 solution from the official website HERE:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
ax = plt.subplot(111)
ax.plot(x, y)
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Only show ticks on the left and bottom spines
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
plt.show()
这篇关于如何删除 matplotlib 中的顶部和右侧轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文