I would like to ask if there is a way to print only the legend box of a figure. 
 


The motiviation for wanting to do this is a work around to the problem of 
having the legend box obscuring data without resorting to "outside" placement 
of the legend.   The idea here is that matplotlib would provide two images:

1. PNG file of figure without legend.
2. PNG file of legend only.

The end user would import both images into another tool (e.g. microsoft power 
point) and arrange figure and legend interactively for the final product.  


Example follows:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 1)
fig, (ax)  = plt.subplots(nrows=1)
ax.plot( x , np.sin(2*np.pi*x) , label='Curve1')
ax.plot( x , np.sin(2*np.pi*x+0.2) , label='Curve2')
ax.set_title('Set default color cycle to rgby')
plt.savefig('without_legend.png',dpi=75)

if True: # Difficult to automatically make a location choice robust
  ax.legend(loc='upper left') # in this particular case, a poor choice for 
placement
else:
  ax.legend(loc='upper right') # in this particular case, a good choice for 
placement

plt.savefig('with_legend.png',dpi=75)

# worst case solution could be post processing these files with imagemagick
#   begin with "composite without_legend.png with_legend.png -compose 
difference alpha_channel.png"
#    ... then filter with alpha_channel.png against with_legend.png
#    ... finally crop this to get "legend_only.png"
------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to