Issue
I plot using two y-axis, on the left and the right of a matplotlib figure and use zorder
to control the position of the plots. I need to define the zorder
across axes in the same figure.
Problem
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10,10,0.01)
fig, ax1 = plt.subplots( 1, 1, figsize=(9,3) )
ax1.plot( x, np.sin(x), color='red', linewidth=10, zorder=1 )
ax2 = ax1.twinx()
ax2.plot( x, x, color='blue', linewidth=10, zorder=-1)
In the previous diagram, I would expect the blue line to appear behind the red plot.
How do I control the zorder
when using twin axes?
I am using:
python: 3.4.3 + numpy: 1.11.0 + matplotlib: 1.5.1
Solution
This should work
ax1.set_zorder(ax2.get_zorder()+1)
ax1.patch.set_visible(False)
Answered By - Dan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.