【问题标题】:Drawing rectangular grid using matplotlib使用 matplotlib 绘制矩形网格
【发布时间】:2015-07-08 00:51:45
【问题描述】:

在 python 中是否有一种简单的方法使用 pyplot (matplotlib) 创建一个矩形网格(像这样,但可能是网格化的),如下所示:

我对python很陌生,可能有一个简单的解决方案,但我一直找不到。

提前致谢。

【问题讨论】:

    标签: python python-2.7 matplotlib


    【解决方案1】:

    目前尚不清楚您要了解哪些细节,但这是一个开始......

    import matplotlib.pyplot as plt
    
    ax = plt.subplot(1, 1, 1)
    ax.spines['left'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['bottom'].set_position('zero')
    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')
    ax.set_xticks(range(-5, 6))
    ax.set_yticks(range(-5, 6))
    ax.set_xlim((-5.5, 5.5))
    ax.set_ylim((-5.5, 5.5))
    ax.grid()
    
    plt.show()
    

    【讨论】:

    • 是的,太好了。我只需要一个例子来为我指明正确的方向。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2022-12-31
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 2015-04-24
    相关资源
    最近更新 更多