|
| 1 | +""" |
| 2 | +You can control the axis tick and grid properties |
| 3 | +""" |
| 4 | + |
| 5 | +from matplotlib.matlab import * |
| 6 | + |
| 7 | +t = arange(0.0, 2.0, 0.01) |
| 8 | +s = sin(2*pi*t) |
| 9 | +plot(t, s) |
| 10 | +grid(True) |
| 11 | + |
| 12 | +# matlab handle graphics style |
| 13 | +xticklines = get(gca(), 'xticklines') |
| 14 | +yticklines = get(gca(), 'yticklines') |
| 15 | +xgridlines = get(gca(), 'xgridlines') |
| 16 | +ygridlines = get(gca(), 'ygridlines') |
| 17 | +xticklabels = get(gca(), 'xticklabels') |
| 18 | +yticklabels = get(gca(), 'yticklabels') |
| 19 | + |
| 20 | +set(xticklines, 'linewidth', 3) |
| 21 | +set(yticklines, 'linewidth', 3) |
| 22 | +set(xgridlines, 'linestyle', '-') |
| 23 | +set(ygridlines, 'linestyle', '-') |
| 24 | +set(yticklabels, 'color', 'r', 'fontsize', 12) |
| 25 | +set(xticklabels, 'color', 'r', 'fontsize', 12) |
| 26 | + |
| 27 | +# keyword args are legal too |
| 28 | +#set(xticklabels, color='r', fontsize=12) |
| 29 | + |
| 30 | +savefig('axprops_demo') |
| 31 | +show() |
| 32 | + |
| 33 | + |
| 34 | +""" |
| 35 | +# the same script, python style |
| 36 | +from matplotlib.matlab import * |
| 37 | +
|
| 38 | +t = arange(0.0, 2.0, 0.01) |
| 39 | +s = sin(2*pi*t) |
| 40 | +ax = subplot(111) |
| 41 | +ax.plot(t, s) |
| 42 | +ax.grid(True) |
| 43 | +
|
| 44 | +ticklines = ax.get_xticklines() |
| 45 | +ticklines.extend( ax.get_yticklines() ) |
| 46 | +gridlines = ax.get_xgridlines() |
| 47 | +gridlines.extend( ax.get_ygridlines() ) |
| 48 | +ticklabels = ax.get_xticklabels() |
| 49 | +ticklabels.extend( ax.get_yticklabels() ) |
| 50 | +
|
| 51 | +for line in ticklines: |
| 52 | + line.set_linewidth(3) |
| 53 | +
|
| 54 | +for line in gridlines: |
| 55 | + line.set_linestyle('-') |
| 56 | +
|
| 57 | +for label in ticklabels: |
| 58 | + label.set_color('r') |
| 59 | + label.set_fontsize(12) |
| 60 | +
|
| 61 | +savefig('axprops_demo') |
| 62 | +show() |
| 63 | +
|
| 64 | +""" |
0 commit comments