From: <jd...@us...> - 2008-07-02 11:08:51
|
Revision: 5705 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5705&view=rev Author: jdh2358 Date: 2008-07-02 04:08:22 -0700 (Wed, 02 Jul 2008) Log Message: ----------- cleaned legend demo example Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/hexbin_demo.py trunk/matplotlib/examples/pylab_examples/legend_demo.py trunk/matplotlib/lib/matplotlib/axes.py Added Paths: ----------- trunk/matplotlib/examples/api/legend_demo.py Added: trunk/matplotlib/examples/api/legend_demo.py =================================================================== --- trunk/matplotlib/examples/api/legend_demo.py (rev 0) +++ trunk/matplotlib/examples/api/legend_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -0,0 +1,41 @@ +import numpy as np +import matplotlib.pyplot as plt + +a = np.arange(0,3,.02) +b = np.arange(0,3,.02) +c = np.exp(a) +d = c[::-1] + +fig = plt.figure() +ax = fig.add_subplot(111) +ax.plot(a,c,'k--',a,d,'k:',a,c+d,'k') +leg = ax.legend(('Model length', 'Data length', 'Total message length'), + 'upper center', shadow=True) +ax.set_ylim([-1,20]) +ax.grid(False) +ax.set_xlabel('Model complexity --->') +ax.set_ylabel('Message length --->') +ax.set_title('Minimum Message Length') + +ax.set_yticklabels([]) +ax.set_xticklabels([]) + +# set some legend properties. All the code below is optional. The +# defaults are usually sensible but if you need more control, this +# shows you how + +# the matplotlib.patches.Rectangle instance surrounding the legend +frame = leg.get_frame() +frame.set_facecolor('0.80') # set the frame face color to light gray + +# matplotlib.text.Text instances +for t in leg.get_texts(): + t.set_fontsize('small') # the legend text fontsize + +# matplotlib.lines.Line2D instances +for l in leg.get_lines(): + l.set_linewidth(1.5) # the legend line width +plt.show() + + + Modified: trunk/matplotlib/examples/pylab_examples/hexbin_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -6,7 +6,9 @@ """ import numpy as np +import matplotlib.cm as cm import matplotlib.pyplot as plt + n = 100000 x = np.random.standard_normal(n) y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) @@ -17,14 +19,14 @@ plt.subplots_adjust(hspace=0.5) plt.subplot(121) -plt.hexbin(x,y) +plt.hexbin(x,y, cmap=cm.jet) plt.axis([xmin, xmax, ymin, ymax]) plt.title("Hexagon binning") cb = plt.colorbar() cb.set_label('counts') plt.subplot(122) -plt.hexbin(x,y,bins='log') +plt.hexbin(x,y,bins='log', cmap=cm.jet) plt.axis([xmin, xmax, ymin, ymax]) plt.title("With a log color scale") cb = plt.colorbar() Modified: trunk/matplotlib/examples/pylab_examples/legend_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -4,32 +4,31 @@ #See http://matplotlib.sf.net/examples/legend_demo2.py for an example #controlling which lines the legend uses and the order +import numpy as np +import matplotlib.pyplot as plt -from pylab import * +a = np.arange(0,3,.02) +b = np.arange(0,3,.02) +c = np.exp(a) +d = c[::-1] -a = arange(0,3,.02) -b = arange(0,3,.02) -c=exp(a) -d=c.tolist() -d.reverse() -d = array(d) +ax = plt.subplot(111) +plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k') +plt.legend(('Model length', 'Data length', 'Total message length'), + 'upper center', shadow=True) +plt.ylim([-1,20]) +plt.grid(False) +plt.xlabel('Model complexity --->') +plt.ylabel('Message length --->') +plt.title('Minimum Message Length') -ax = subplot(111) -plot(a,c,'k--',a,d,'k:',a,c+d,'k') -legend(('Model length', 'Data length', 'Total message length'), - 'upper center', shadow=True) -ax.set_ylim([-1,20]) -ax.grid(0) -xlabel('Model complexity --->') -ylabel('Message length --->') -title('Minimum Message Length') -setp(gca(), 'yticklabels', []) -setp(gca(), 'xticklabels', []) +plt.setp(plt.gca(), 'yticklabels', []) +plt.setp(plt.gca(), 'xticklabels', []) # set some legend properties. All the code below is optional. The # defaults are usually sensible but if you need more control, this # shows you how -leg = gca().get_legend() +leg = plt.gca().get_legend() ltext = leg.get_texts() # all the text.Text instance in the legend llines = leg.get_lines() # all the lines.Line2D instance in the legend frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend @@ -37,11 +36,11 @@ # see text.Text, lines.Line2D, and patches.Rectangle for more info on # the settable properties of lines, text, and rectangles frame.set_facecolor('0.80') # set the frame face color to light gray -setp(ltext, fontsize='small') # the legend text fontsize -setp(llines, linewidth=1.5) # the legend linewidth +plt.setp(ltext, fontsize='small') # the legend text fontsize +plt.setp(llines, linewidth=1.5) # the legend linewidth #leg.draw_frame(False) # don't draw the legend frame -#savefig('legend_demo') -show() +#plt.savefig('legend_demo') +plt.show() Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-07-01 12:01:38 UTC (rev 5704) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-07-02 11:08:22 UTC (rev 5705) @@ -3592,7 +3592,7 @@ **Example:** - .. plot:: legend_demo.py + .. plot:: ../mpl_examples/api/legend_demo.py """ def get_handles(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |