【发布时间】:2012-03-17 14:21:10
【问题描述】:
我正在尝试在 matplotlib 中绘制数据。我想隐藏盒子的上部和右侧。有谁知道如何做到这一点?
感谢您的帮助
【问题讨论】:
-
@Joe:谢谢,我不知道 Matplotlib 中“脊椎”的概念。
标签: python plot matplotlib
我正在尝试在 matplotlib 中绘制数据。我想隐藏盒子的上部和右侧。有谁知道如何做到这一点?
感谢您的帮助
【问题讨论】:
标签: python plot matplotlib
只需将刺(和/或刻度)设置为不可见。
例如
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.show()
如果您还想隐藏顶部和左侧的刻度,只需执行以下操作:
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
【讨论】:
也考虑这个选项:
import matplotlib.pyplot as plt
# Create your plot with your code
# Then extract the spines and make them invisible
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.show() # Show your plot
或者只是
import matplotlib.pyplot as plt
# Create your plot with your code
# Then extract the spines and make them invisible
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
plt.show() # Show your plot
希望对某人有所帮助
【讨论】: