matplotlib - 绘图排序/分层 Julia pyplot

标签 matplotlib julia scatter

我有一个绘制线 (x,y) 和特定点 (xx,yy) 的子图。我想突出显示 (xx,yy),因此我用scatter 绘制了它。但是,即使我将其排序在原始图之后,新点仍然显示在原始线后面。我怎样才能解决这个问题? MWE如下。

x = 1:10
y = 1:10
xx = 5
yy = 5
fig, ax = subplots()
ax[:plot](x,y)
ax[:scatter](xx,yy, color="red", label="h_star", s=100)
legend()
xlabel("x")
ylabel("y")
title("test")
grid("on")

最佳答案

您可以使用参数 zorder 更改显示在彼此之上的图。显示的 matplotlib 示例 here简单解释一下:

The default drawing order for axes is patches, lines, text. This order is determined by the zorder attribute. The following defaults are set

Artist                      Z-order

Patch / PatchCollection      1

Line2D / LineCollection      2

Text                         3

You can change the order for individual artists by setting the zorder. Any individual plot() call can set a value for the zorder of that particular item.

基于问题中的代码,使用python的完整示例如下所示:

import matplotlib.pyplot as plt

x = range(1,10)
y = range(1,10)
xx = 5
yy = 5
fig, ax = plt.subplots()
ax.plot(x,y)

# could set zorder very high, say 10, to "make sure" it will be on the top
ax.scatter(xx,yy, color="red", label="h_star", s=100, zorder=3)

plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.title("test")
plt.grid("on")

plt.show()

这给出:

enter image description here

关于matplotlib - 绘图排序/分层 Julia pyplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48106547/

相关文章:

arrays - 如何从 Julia 匹配谓词中的数组中选择元素?

haskell - Julia 是否有类似于 Haskell 的美元符号的运算符?

在散点图中绘制最小二乘线

python - 通过循环和函数填充 matplotlib 子图

python - pandas "stacked"条形图,其中未添加值以给出高度

python - 如何在matplotlib中删除一刻度的轴标签

julia - 在 Julia 中将十六进制字符串转换为 base64

Python根据距离均匀分散固定中心周围的坐标

python - 使用 legend_elements 设置散点图图例标签

python - 未使用 Matplotlib 绘制线条/轨迹