|
From: Stephen G. <ste...@op...> - 2011-09-28 07:31:34
|
On 28/09/2011 4:32 PM, Klonuo Umom wrote:
> Please consider:
>
> plot([1, 2, 3, 4], label='line 1')
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
>
> will draw only label for 'line 2'
>
> plot([1, 2, 3, 4], label='line 1')
> legend()
> twinx()
> plot([11, 12, 11, 14], label='line 2')
> legend()
>
>
> same result, as it will overwrite label 'line 1' with label 'line 2'
>
> How to deal with this, without manually positioning legends and if
> possible including all annotated plot lines in one legend?
>
>
> Thanks
>
I would do something like
from matplotlib import pylab
LegendText = []
pylab.twinx() # << had to move before first plot else it blew up
pylab.plot([1, 2, 3, 4] )
LegendText.append('line 1')
pylab.plot([11, 12, 11, 14])
LegendText.append('line 2')
pylab.legend( LegendText , loc='lower right')
pylab.show()
Don't know if there is a better way
Steve
|