I'm having trouble with the legends in a simple pandas plotting task. It seems the second legend is being hidden by the first graph.
A sample of my df:
print(campaign.head(10))
hour_read hour_sent
0 16.0 13
1 14.0 13
2 13.0 13
3 14.0 13
4 NaN 13
5 13.0 13
6 13.0 13
7 16.0 13
8 14.0 13
9 16.0 13
10 15.0 15
11 16.0 15
12 15.0 15
13 15.0 15
14 15.0 15
I can plot both these series on the same histogram, and I am using `secondary_y'.
However I can't get the legend for hour_read
to appear. No matter what I try with the legend options.
plt.figure(figsize=(15,8))
plt.xlabel('Email sent vs open hour')
campaign.hour_read.plot(kind='hist',alpha=0.8, label='Hour Read')
campaign.hour_sent.plot(kind='hist',alpha=0.8 ,secondary_y=True, label='Hour Sent')
plt.legend(loc='upper right')
plt.show()
I have also tried setting up separate axes first. And using #ax1.legend(loc=1)
and ax2.legend(loc=2)
with many different variations. I think the hour sent
plot is completely covering the hour_read
legend. How can I get around this?