【问题标题】:Matplotlib: draw grid behind everything elseMatplotlib:在其他所有内容后面绘制网格
【发布时间】:2021-02-07 08:17:57
【问题描述】:

给定以下示例代码,它绘制了一个椭圆,我怎样才能使网格线出现在其他所有内容的后面?

#!/usr/bin/python3
from pylab import *
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
grid()
ax.add_artist( Ellipse( xy = (0,0), width = 1, height = 2, angle = 0, edgecolor='b', lw=4, facecolor='green' ) )
show()

本网站上类似问题的答案在我的案例中不起作用。你能给出一个完整的工作示例吗?

【问题讨论】:

标签: python python-3.x matplotlib


【解决方案1】:

您需要使用zorder 参数。进行此修改,它将起作用。

ax.add_artist( Ellipse( xy = (0,0), width = 1, height = 2, angle = 0, edgecolor='b', lw=4, facecolor='green' ,zorder=2) )

在绘制多个项目时,您可以使用zorder 控制它们出现的顺序。在zoderhere上查找更多信息。

这个简单的修复使这个数字偏离了这个:

到这里:

【讨论】:

    猜你喜欢
    • 2010-12-16
    • 2014-06-14
    • 2019-03-25
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多