|
4 | 4 | #See http://matplotlib.sf.net/examples/legend_demo2.py for an example |
5 | 5 | #controlling which lines the legend uses and the order |
6 | 6 |
|
7 | | - |
8 | | -from pylab import * |
9 | | - |
10 | | -a = arange(0,3,.02) |
11 | | -b = arange(0,3,.02) |
12 | | -c=exp(a) |
13 | | -d=c.tolist() |
14 | | -d.reverse() |
15 | | -d = array(d) |
16 | | - |
17 | | -ax = subplot(111) |
18 | | -plot(a,c,'k--',a,d,'k:',a,c+d,'k') |
19 | | -legend(('Model length', 'Data length', 'Total message length'), |
20 | | - 'upper center', shadow=True) |
21 | | -ax.set_ylim([-1,20]) |
22 | | -ax.grid(0) |
23 | | -xlabel('Model complexity --->') |
24 | | -ylabel('Message length --->') |
25 | | -title('Minimum Message Length') |
26 | | -setp(gca(), 'yticklabels', []) |
27 | | -setp(gca(), 'xticklabels', []) |
| 7 | +import numpy as np |
| 8 | +import matplotlib.pyplot as plt |
| 9 | + |
| 10 | +a = np.arange(0,3,.02) |
| 11 | +b = np.arange(0,3,.02) |
| 12 | +c = np.exp(a) |
| 13 | +d = c[::-1] |
| 14 | + |
| 15 | +ax = plt.subplot(111) |
| 16 | +plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k') |
| 17 | +plt.legend(('Model length', 'Data length', 'Total message length'), |
| 18 | + 'upper center', shadow=True) |
| 19 | +plt.ylim([-1,20]) |
| 20 | +plt.grid(False) |
| 21 | +plt.xlabel('Model complexity --->') |
| 22 | +plt.ylabel('Message length --->') |
| 23 | +plt.title('Minimum Message Length') |
| 24 | + |
| 25 | +plt.setp(plt.gca(), 'yticklabels', []) |
| 26 | +plt.setp(plt.gca(), 'xticklabels', []) |
28 | 27 |
|
29 | 28 | # set some legend properties. All the code below is optional. The |
30 | 29 | # defaults are usually sensible but if you need more control, this |
31 | 30 | # shows you how |
32 | | -leg = gca().get_legend() |
| 31 | +leg = plt.gca().get_legend() |
33 | 32 | ltext = leg.get_texts() # all the text.Text instance in the legend |
34 | 33 | llines = leg.get_lines() # all the lines.Line2D instance in the legend |
35 | 34 | frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
36 | 35 |
|
37 | 36 | # see text.Text, lines.Line2D, and patches.Rectangle for more info on |
38 | 37 | # the settable properties of lines, text, and rectangles |
39 | 38 | frame.set_facecolor('0.80') # set the frame face color to light gray |
40 | | -setp(ltext, fontsize='small') # the legend text fontsize |
41 | | -setp(llines, linewidth=1.5) # the legend linewidth |
| 39 | +plt.setp(ltext, fontsize='small') # the legend text fontsize |
| 40 | +plt.setp(llines, linewidth=1.5) # the legend linewidth |
42 | 41 | #leg.draw_frame(False) # don't draw the legend frame |
43 | | -#savefig('legend_demo') |
44 | | -show() |
| 42 | +#plt.savefig('legend_demo') |
| 43 | +plt.show() |
45 | 44 |
|
46 | 45 |
|
47 | 46 |
|
0 commit comments