如何在matplotlib中删除上轴和右轴? [英] How can I remove the top and right axis in matplotlib?

查看:123
本文介绍了如何在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.

推荐答案

这是官方网站这里:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆