FJDU
FJDU

Reputation: 1473

Plot over subplot

I have a subplot inside an existing axes frame, and in the subplot there are some lines or filled contourf plot. What I want to do is to plot some lines in the existing bigger frame, and these lines must be on top of the lines/contourf in the subfigure. The following is a small example. Basically I want the blue and/or green lines to be on top of the red line. It seems setting the zorder has no effect for lines belonging to different sub-axes.

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot([0,2], color='blue', zorder=300)
ax0 = gca()
ax = fig.add_axes([0.3,0.3,0.3,0.3], zorder=0, axisbg='none')
ax.plot([0,1],[1,0], linewidth=40, color='red', zorder=-100)
ax0.plot([0.55,0.55],[0,2], linewidth=20, color='green', zorder=200)

Upvotes: 0

Views: 703

Answers (1)

FJDU
FJDU

Reputation: 1473

I kind of find a solution, which may not be perfect but works for my needs. The trick is to set the big axes frame to a high zorder, and set its background color to transparent, so that the small axes frame in the background can be seen, and in this way the lines in the main frame will naturally be on top of the lines in the small frame.

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot([0,2], color='blue')
ax0 = gca()
ax0.set_zorder(100)
ax0.set_axis_bgcolor('none')
ax = fig.add_axes([0.3,0.3,0.3,0.3], zorder=0, axisbg='none')
ax.plot([0,1],[1,0], linewidth=40, color='red')
ax0.plot([0.55,0.55],[0,2], linewidth=20, color='green')

Upvotes: 3

Related Questions