【问题标题】:How to display only a left and bottom box border in matplotlib?如何在 matplotlib 中只显示左边框和下边框?
【发布时间】:2012-03-17 14:21:10
【问题描述】:

我正在尝试在 matplotlib 中绘制数据。我想隐藏盒子的上部和右侧。有谁知道如何做到这一点?

感谢您的帮助

【问题讨论】:

  • @Joe:谢谢,我不知道 Matplotlib 中“脊椎”的概念。

标签: python plot matplotlib


【解决方案1】:

只需将刺(和/或刻度)设置为不可见。

例如

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')

【讨论】:

    【解决方案2】:

    也考虑这个选项:

    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
    

    希望对某人有所帮助

    【讨论】:

      猜你喜欢
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 2011-08-16
      • 2015-09-15
      • 1970-01-01
      • 2012-10-06
      相关资源
      最近更新 更多