|
1 | | -#!/usr/bin/env python |
2 | | -# |
3 | | -# matplotlib now has a PolarAxes class and a polar function in the |
4 | | -# matplotlib interface. This is considered alpha and the interface |
5 | | -# may change as we work out how polar axes should best be integrated |
6 | | -# |
7 | | -# The only function that has been tested on polar axes is "plot" (the |
8 | | -# pylab interface function "polar" calls ax.plot where ax is a |
9 | | -# PolarAxes) -- other axes plotting functions may work on PolarAxes |
10 | | -# but haven't been tested and may need tweaking. |
11 | | -# |
12 | | -# you can get a PolarSubplot instance by doing, for example |
13 | | -# |
14 | | -# subplot(211, polar=True) |
15 | | -# |
16 | | -# or a PolarAxes instance by doing |
17 | | -# axes([left, bottom, width, height], polar=True) |
18 | | -# |
19 | | -# The view limits (eg xlim and ylim) apply to the lower left and upper |
20 | | -# right of the rectangular box that surrounds to polar axes. e.g., if |
21 | | -# you have |
22 | | -# |
23 | | -# r = arange(0,1,0.01) |
24 | | -# theta = 2*pi*r |
25 | | -# |
26 | | -# the lower left corner is 5/4pi, sqrt(2) and the |
27 | | -# upper right corner is 1/4pi, sqrt(2) |
28 | | -# |
29 | | -# you could change the radial bounding box (zoom out) by setting the |
30 | | -# ylim (radial coordinate is the second argument to the plot command, |
31 | | -# as in MATLAB, though this is not advised currently because it is not |
32 | | -# clear to me how the axes should behave in the change of view limits. |
33 | | -# Please advise me if you have opinions. Likewise, the pan/zoom |
34 | | -# controls probably do not do what you think they do and are better |
35 | | -# left alone on polar axes. Perhaps I will disable them for polar |
36 | | -# axes unless we come up with a meaningful, useful and functional |
37 | | -# implementation for them. |
38 | | -# |
39 | | -# See the pylab rgrids and thetagrids functions for |
40 | | -# information on how to customize the grid locations and labels |
41 | | -import matplotlib |
| 1 | +""" |
| 2 | +Demo of a line plot on a polar axis. |
| 3 | +""" |
42 | 4 | import numpy as np |
43 | | -from matplotlib.pyplot import figure, show, rc, grid |
| 5 | +import matplotlib.pyplot as plt |
44 | 6 |
|
45 | | -# radar green, solid grid lines |
46 | | -rc('grid', color='#316931', linewidth=1, linestyle='-') |
47 | | -rc('xtick', labelsize=15) |
48 | | -rc('ytick', labelsize=15) |
49 | | - |
50 | | -# force square figure and square axes looks better for polar, IMO |
51 | | -width, height = matplotlib.rcParams['figure.figsize'] |
52 | | -size = min(width, height) |
53 | | -# make a square figure |
54 | | -fig = figure(figsize=(size, size)) |
55 | | -ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c') |
56 | 7 |
|
57 | 8 | r = np.arange(0, 3.0, 0.01) |
58 | | -theta = 2*np.pi*r |
59 | | -ax.plot(theta, r, color='#ee8d18', lw=3) |
| 9 | +theta = 2 * np.pi * r |
| 10 | + |
| 11 | +ax = plt.subplot(111, polar=True) |
| 12 | +ax.plot(theta, r, color='r', linewidth=3) |
60 | 13 | ax.set_rmax(2.0) |
61 | | -grid(True) |
| 14 | +ax.grid(True) |
62 | 15 |
|
63 | | -ax.set_title("And there was much rejoicing!", fontsize=20) |
64 | | -show() |
| 16 | +ax.set_title("A line plot on a polar axis", va='bottom') |
| 17 | +plt.show() |
0 commit comments