From: Jeff Kowalczyk <jtk@ya...> - 2011-02-25 23:35:19
I am trying to plot multiple series on one axes and a bar chart on a shared x,
new y axes. I'm using twinx. The following test code works, but I need to render
the bar plot *behind* the line plots. Can I somehow control zorder globally
within a figure?
Alternatively, I could make the bar chart the first plot/axes ax1, but the
position for its y-axis must be on the right, the line chart's y-axis on the
left. Can this be controlled?
import numpy as np
import matplotlib.pyplot as plt
width_bar = 0.4
width_line = 6
for i in range(0,1):
data = np.loadtxt(open('test.csv','r'), delimiter=',',
'formats': ('f4', 'i4', 'i4', 'i4', 'i4')},
x,y1,y2,count = data['x'],data['y1'],data['y2'],data['count']
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1, linewidth=width_line, zorder=3)
ax1.plot(x, y2, linewidth=width_line, zorder=2)
ax2 = ax1.twinx()
ax2.bar(x, count, width=width_bar, color='0.9', zorder=1)
Jeff Kowalczyk, on 2011-02-25 23:20, wrote:
> I am trying to plot multiple series on one axes and a bar chart on a shared x,
> new y axes. I'm using twinx. The following test code works, but I need to render
> the bar plot *behind* the line plots. Can I somehow control zorder globally
> within a figure?
add these two lines before your plt.show()
ax1.set_zorder(ax2.get_zorder()+1) # put ax in front of ax2
ax1.patch.set_visible(False) # hide the 'canvas'
> Alternatively, I could make the bar chart the first plot/axes ax1, but the
> position for its y-axis must be on the right, the line chart's y-axis on the
> left. Can this be controlled?
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7