情节排序/分层julia pyplot [英] plot ordering/layering julia pyplot
问题描述
我有一个子图可以绘制一条线(x,y)和一个特定点(xx,yy).我想高亮(xx,yy),所以用scatter
绘制了它.但是,即使我在原始绘图之后对其进行排序,新点仍会显示在原始线的后面.我怎样才能解决这个问题?下面是MWE.
I have a subplot that plots a line (x,y) and a particular point (xx,yy). I want to highligh (xx,yy), so I've plotted it with scatter
. However, even if I order it after the original plot, the new point still shows up behind the original line. How can I fix this? MWE below.
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示例给出了简要说明:
You can change which plots are displayed on top of each other with the argument zorder
. The matplotlib example shown here gives a brief explanation:
轴的默认绘制顺序是面片,线条,文本.这 顺序由zorder属性确定.以下默认值 被设置
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
您可以通过设置zorder来更改单个艺术家的顺序. 任何单独的plot()调用都可以为该zorder设置一个值 特定项目.
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 如下所示:
A full example based on the code in the question, using python is shown below:
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()
哪个给:
这篇关于情节排序/分层julia pyplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!