0

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)

1 Answer 1

3

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')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it worked for me. It looks like set_axis_bgcolor was replaced by set_facecolor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.