2017-03-03 8 views
0

그리기 도면은 Artist 전에 구성되어 있지만, 두 번째는, 전경에 항상 표시 streamplotArtist :Streamplot 항상 전경

enter image description here

pcolormesh 함께 할 같은 예상과 같습니다

enter image description here

이것은 두 그림의 코드입니다.

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.patches import Rectangle 

Y, X = np.mgrid[-3:3:100j, -3:3:100j] 
U = -1 - X**2 + Y 
V = 1 + X - Y**2 
speed = np.sqrt(U*U + V*V) 

fig0, ax0 = plt.subplots() 
working = False 
if working: 
    strm = ax0.pcolormesh(X, Y, U, cmap=plt.cm.autumn) 
else: 
    strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) 
    fig0.colorbar(strm.lines) 

#fig1, (ax1, ax2) = plt.subplots(ncols=2) 
#ax1.streamplot(X, Y, U, V, density=[0.5, 1]) 
# 
#lw = 5*speed/speed.max() 
#ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) 

e = Rectangle(xy=(0,0), width=1, height=1) 
e.set_facecolor([0.9,0.9,0.9]) 
ax0.add_artist(e) 

plt.show() 

Artiststreamplot을 오버레이합니까?

답변

2

아티스트의 z- 순서를 변경할 수 있습니다. 귀하의 예를 들어보십시오

e = Rectangle(xy=(0,0), width=1, height=1, zorder=10) 

a matplotlib example에 따르면, 기본 z 순서는 것 같다 :

  • 패치/PatchCollection => 1
  • 된 Line2D/LineCollection => 2
  • 텍스트 => 3

이렇게하면 왜 스트리 플로트 (선)가 사각형의 상단에 그려지는지 설명 할 수 있습니다. e (패치).

+0

아, 너무 단순 : streamplot에는 zorder 매개 변수가 없으므로 작동하지 않을 것이라고 생각했습니다. 고맙습니다! –