Python matplotlib.pyplot.polar() Examples
The following are 30
code examples of matplotlib.pyplot.polar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: test_axes.py From neural-network-animation with MIT License | 8 votes |
def test_markevery_polar(): cases = [None, 8, (30, 8), [16, 24, 30], [0,-1], slice(100, 200, 3), 0.1, 0.3, 1.5, (0.0, 0.1), (0.45, 0.1)] cols = 3 gs = matplotlib.gridspec.GridSpec(len(cases) // cols + 1, cols) r = np.linspace(0, 3.0, 200) theta = 2 * np.pi * r for i, case in enumerate(cases): row = (i // cols) col = i % cols plt.subplot(gs[row, col], polar = True) plt.title('markevery=%s' % str(case)) plt.plot(theta, r, 'o', ls='-', ms=4, markevery=case)
Example #2
Source File: test_axes.py From neural-network-animation with MIT License | 6 votes |
def test_polar_wrap(): D2R = np.pi / 180.0 fig = plt.figure() plt.subplot(111, polar=True) plt.polar([179*D2R, -179*D2R], [0.2, 0.1], "b.-") plt.polar([179*D2R, 181*D2R], [0.2, 0.1], "g.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3]) assert len(fig.axes) == 1, 'More than one polar axes created.' fig = plt.figure() plt.subplot(111, polar=True) plt.polar([2*D2R, -2*D2R], [0.2, 0.1], "b.-") plt.polar([2*D2R, 358*D2R], [0.2, 0.1], "g.-") plt.polar([358*D2R, 2*D2R], [0.2, 0.1], "r.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3])
Example #3
Source File: test_axes.py From ImageFusion with MIT License | 6 votes |
def test_markevery_polar(): cases = [None, 8, (30, 8), [16, 24, 30], [0,-1], slice(100, 200, 3), 0.1, 0.3, 1.5, (0.0, 0.1), (0.45, 0.1)] cols = 3 gs = matplotlib.gridspec.GridSpec(len(cases) // cols + 1, cols) r = np.linspace(0, 3.0, 200) theta = 2 * np.pi * r for i, case in enumerate(cases): row = (i // cols) col = i % cols plt.subplot(gs[row, col], polar = True) plt.title('markevery=%s' % str(case)) plt.plot(theta, r, 'o', ls='-', ms=4, markevery=case)
Example #4
Source File: test_axes.py From ImageFusion with MIT License | 6 votes |
def test_polar_wrap(): D2R = np.pi / 180.0 fig = plt.figure() plt.subplot(111, polar=True) plt.polar([179*D2R, -179*D2R], [0.2, 0.1], "b.-") plt.polar([179*D2R, 181*D2R], [0.2, 0.1], "g.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3]) assert len(fig.axes) == 1, 'More than one polar axes created.' fig = plt.figure() plt.subplot(111, polar=True) plt.polar([2*D2R, -2*D2R], [0.2, 0.1], "b.-") plt.polar([2*D2R, 358*D2R], [0.2, 0.1], "g.-") plt.polar([358*D2R, 2*D2R], [0.2, 0.1], "r.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3])
Example #5
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_gridlines(): fig = plt.figure() ax = fig.add_subplot(111, polar=True) # make all major grid lines lighter, only x grid lines set in 2.1.0 ax.grid(alpha=0.2) # hide y tick labels, no effect in 2.1.0 plt.setp(ax.yaxis.get_ticklabels(), visible=False) fig.canvas.draw() assert ax.xaxis.majorTicks[0].gridline.get_alpha() == .2 assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2
Example #6
Source File: sync.py From pyclustering with GNU General Public License v3.0 | 5 votes |
def animate(sync_output_dynamic, title=None, save_movie=None): """! @brief Shows animation of phase coordinates and animation of correlation matrix together for the Sync dynamic output on the same figure. @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network. @param[in] title (string): Title of the animation that is displayed on a figure if it is specified. @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter. """ dynamic = sync_output_dynamic.output[0] correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(0) figure = plt.figure(1) if title is not None: figure.suptitle(title, fontsize = 26, fontweight = 'bold') ax1 = figure.add_subplot(121, projection='polar') ax2 = figure.add_subplot(122) artist1, = ax1.plot(dynamic, [1.0] * len(dynamic), marker='o', color='blue', ls='') artist2 = ax2.imshow(correlation_matrix, cmap = plt.get_cmap('Accent'), interpolation='kaiser') def init_frame(): return [artist1, artist2] def frame_generation(index_dynamic): dynamic = sync_output_dynamic.output[index_dynamic] artist1.set_data(dynamic, [1.0] * len(dynamic)) correlation_matrix = sync_output_dynamic.allocate_correlation_matrix(index_dynamic) artist2.set_data(correlation_matrix) return [artist1, artist2] dynamic_animation = animation.FuncAnimation(figure, frame_generation, len(sync_output_dynamic), interval=75, init_func=init_frame, repeat_delay=5000) if save_movie is not None: dynamic_animation.save(save_movie, writer='ffmpeg', fps=15, bitrate=1500) else: plt.show()
Example #7
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_annotations(): # you can specify the xypoint and the xytext in different # positions and coordinate systems, and optionally turn on a # connecting line and mark the point with a marker. Annotations # work on polar axes too. In the example below, the xy point is # in native coordinates (xycoords defaults to 'data'). For a # polar axes, this is in (theta, radius) space. The text in this # example is placed in the fractional figure coordinate system. # Text keyword args like horizontal and vertical alignment are # respected # Setup some data r = np.arange(0.0, 1.0, 0.001) theta = 2.0 * 2.0 * np.pi * r fig = plt.figure() ax = fig.add_subplot(111, polar=True) line, = ax.plot(theta, r, color='#ee8d18', lw=3) line, = ax.plot((0, 0), (0, 1), color="#0000ff", lw=1) ind = 800 thisr, thistheta = r[ind], theta[ind] ax.plot([thistheta], [thisr], 'o') ax.annotate('a polar annotation', xy=(thistheta, thisr), # theta, radius xytext=(0.05, 0.05), # fraction, fraction textcoords='figure fraction', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', ) ax.tick_params(axis='x', tick1On=True, tick2On=True, direction='out')
Example #8
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_coord_annotations(): # You can also use polar notation on a catesian axes. Here the # native coordinate system ('data') is cartesian, so you need to # specify the xycoords and textcoords as 'polar' if you want to # use (theta, radius) from matplotlib.patches import Ellipse el = Ellipse((0, 0), 10, 20, facecolor='r', alpha=0.5) fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_artist(el) el.set_clip_box(ax.bbox) ax.annotate('the top', xy=(np.pi/2., 10.), # theta, radius xytext=(np.pi/3, 20.), # theta, radius xycoords='polar', textcoords='polar', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', clip_on=True, # clip to the axes bounding box ) ax.set_xlim(-20, 20) ax.set_ylim(-20, 20)
Example #9
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_alignment(): ''' Test that changing the vertical/horizontal alignment of a polar graph works as expected ''' ranges = [(0, 5), (0, 5)] angles = np.arange(0, 360, 90) levels = 5 fig = plt.figure() figureSize = [0.1, 0.1, 0.8, 0.8] horizontal = fig.add_axes(figureSize, polar=True, label='horizontal') vertical = fig.add_axes(figureSize, polar=True, label='vertical') axes = [horizontal, vertical] horizontal.set_thetagrids(angles) vertical.patch.set_visible(False) for i in range(2): grid = np.linspace(*ranges[i], num=levels) gridValues = [0, 0.2, 0.4, 0.6, 0.8, 1] axes[i].set_rgrids(gridValues, angle=angles[i], horizontalalignment='left', verticalalignment='top')
Example #10
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_wrap(): fig = plt.figure() plt.subplot(111, polar=True) plt.polar(np.deg2rad([179, -179]), [0.2, 0.1], "b.-") plt.polar(np.deg2rad([179, 181]), [0.2, 0.1], "g.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3]) assert len(fig.axes) == 1, 'More than one polar axes created.' fig = plt.figure() plt.subplot(111, polar=True) plt.polar(np.deg2rad([2, -2]), [0.2, 0.1], "b.-") plt.polar(np.deg2rad([2, 358]), [0.2, 0.1], "g.-") plt.polar(np.deg2rad([358, 2]), [0.2, 0.1], "r.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3])
Example #11
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_units(): import matplotlib.testing.jpl_units as units units.register() pi = np.pi deg = units.deg km = units.km x1 = [pi/6.0, pi/4.0, pi/3.0, pi/2.0] x2 = [30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg] y1 = [1.0, 2.0, 3.0, 4.0] y2 = [4.0, 3.0, 2.0, 1.0] fig = plt.figure() plt.polar(x2, y1, color="blue") # polar(x2, y1, color = "red", xunits="rad") # polar(x2, y2, color = "green") fig = plt.figure() # make sure runits and theta units work y1 = [y*km for y in y1] plt.polar(x2, y1, color="blue", thetaunits="rad", runits="km") assert isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter)
Example #12
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_negative_rmin(): r = np.arange(-3.0, 0.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_rmax(0.0) ax.set_rmin(-3.0)
Example #13
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_rorigin(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_rmax(2.0) ax.set_rmin(0.5) ax.set_rorigin(0.0)
Example #14
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_theta_position(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_theta_zero_location("NW", 30) ax.set_theta_direction('clockwise')
Example #15
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_rlabel_position(): fig = plt.figure() ax = fig.add_subplot(111, projection='polar') ax.set_rlabel_position(315) ax.tick_params(rotation='auto')
Example #16
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_polar_theta_limits(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r theta_mins = np.arange(15.0, 361.0, 90.0) theta_maxs = np.arange(50.0, 361.0, 90.0) DIRECTIONS = ('out', 'in', 'inout') fig, axes = plt.subplots(len(theta_mins), len(theta_maxs), subplot_kw={'polar': True}, figsize=(8, 6)) for i, start in enumerate(theta_mins): for j, end in enumerate(theta_maxs): ax = axes[i, j] ax.plot(theta, r) if start < end: ax.set_thetamin(start) ax.set_thetamax(end) else: # Plot with clockwise orientation instead. ax.set_thetamin(end) ax.set_thetamax(start) ax.set_theta_direction('clockwise') ax.tick_params(tick1On=True, tick2On=True, direction=DIRECTIONS[i % len(DIRECTIONS)], rotation='auto') ax.yaxis.set_tick_params(label2On=True, rotation='auto')
Example #17
Source File: test_axes.py From neural-network-animation with MIT License | 5 votes |
def test_polar_coord_annotations(): # You can also use polar notation on a catesian axes. Here the # native coordinate system ('data') is cartesian, so you need to # specify the xycoords and textcoords as 'polar' if you want to # use (theta, radius) from matplotlib.patches import Ellipse el = Ellipse((0, 0), 10, 20, facecolor='r', alpha=0.5) fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_artist(el) el.set_clip_box(ax.bbox) ax.annotate('the top', xy=(np.pi/2., 10.), # theta, radius xytext=(np.pi/3, 20.), # theta, radius xycoords='polar', textcoords='polar', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', clip_on=True, # clip to the axes bounding box ) ax.set_xlim(-20, 20) ax.set_ylim(-20, 20)
Example #18
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_annotations(): # you can specify the xypoint and the xytext in different # positions and coordinate systems, and optionally turn on a # connecting line and mark the point with a marker. Annotations # work on polar axes too. In the example below, the xy point is # in native coordinates (xycoords defaults to 'data'). For a # polar axes, this is in (theta, radius) space. The text in this # example is placed in the fractional figure coordinate system. # Text keyword args like horizontal and vertical alignment are # respected # Setup some data r = np.arange(0.0, 1.0, 0.001) theta = 2.0 * 2.0 * np.pi * r fig = plt.figure() ax = fig.add_subplot(111, polar=True) line, = ax.plot(theta, r, color='#ee8d18', lw=3) line, = ax.plot((0, 0), (0, 1), color="#0000ff", lw=1) ind = 800 thisr, thistheta = r[ind], theta[ind] ax.plot([thistheta], [thisr], 'o') ax.annotate('a polar annotation', xy=(thistheta, thisr), # theta, radius xytext=(0.05, 0.05), # fraction, fraction textcoords='figure fraction', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', ) ax.tick_params(axis='x', tick1On=True, tick2On=True, direction='out')
Example #19
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_coord_annotations(): # You can also use polar notation on a catesian axes. Here the # native coordinate system ('data') is cartesian, so you need to # specify the xycoords and textcoords as 'polar' if you want to # use (theta, radius) from matplotlib.patches import Ellipse el = Ellipse((0, 0), 10, 20, facecolor='r', alpha=0.5) fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_artist(el) el.set_clip_box(ax.bbox) ax.annotate('the top', xy=(np.pi/2., 10.), # theta, radius xytext=(np.pi/3, 20.), # theta, radius xycoords='polar', textcoords='polar', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', clip_on=True, # clip to the axes bounding box ) ax.set_xlim(-20, 20) ax.set_ylim(-20, 20)
Example #20
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_alignment(): ''' Test that changing the vertical/horizontal alignment of a polar graph works as expected ''' ranges = [(0, 5), (0, 5)] angles = np.arange(0, 360, 90) levels = 5 fig = plt.figure() figureSize = [0.1, 0.1, 0.8, 0.8] horizontal = fig.add_axes(figureSize, polar=True, label='horizontal') vertical = fig.add_axes(figureSize, polar=True, label='vertical') axes = [horizontal, vertical] horizontal.set_thetagrids(angles) vertical.patch.set_visible(False) for i in range(2): grid = np.linspace(*ranges[i], num=levels) gridValues = [0, 0.2, 0.4, 0.6, 0.8, 1] axes[i].set_rgrids(gridValues, angle=angles[i], horizontalalignment='left', verticalalignment='top')
Example #21
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_wrap(): fig = plt.figure() plt.subplot(111, polar=True) plt.polar(np.deg2rad([179, -179]), [0.2, 0.1], "b.-") plt.polar(np.deg2rad([179, 181]), [0.2, 0.1], "g.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3]) assert len(fig.axes) == 1, 'More than one polar axes created.' fig = plt.figure() plt.subplot(111, polar=True) plt.polar(np.deg2rad([2, -2]), [0.2, 0.1], "b.-") plt.polar(np.deg2rad([2, 358]), [0.2, 0.1], "g.-") plt.polar(np.deg2rad([358, 2]), [0.2, 0.1], "r.-") plt.rgrids([0.05, 0.1, 0.15, 0.2, 0.25, 0.3])
Example #22
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_units(): import matplotlib.testing.jpl_units as units units.register() pi = np.pi deg = units.deg km = units.km x1 = [pi/6.0, pi/4.0, pi/3.0, pi/2.0] x2 = [30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg] y1 = [1.0, 2.0, 3.0, 4.0] y2 = [4.0, 3.0, 2.0, 1.0] fig = plt.figure() plt.polar(x2, y1, color="blue") # polar(x2, y1, color = "red", xunits="rad") # polar(x2, y2, color = "green") fig = plt.figure() # make sure runits and theta units work y1 = [y*km for y in y1] plt.polar(x2, y1, color="blue", thetaunits="rad", runits="km") assert isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter)
Example #23
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_negative_rmin(): r = np.arange(-3.0, 0.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_rmax(0.0) ax.set_rmin(-3.0)
Example #24
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_rorigin(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_rmax(2.0) ax.set_rmin(0.5) ax.set_rorigin(0.0)
Example #25
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_theta_position(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_theta_zero_location("NW", 30) ax.set_theta_direction('clockwise')
Example #26
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_rlabel_position(): fig = plt.figure() ax = fig.add_subplot(111, projection='polar') ax.set_rlabel_position(315) ax.tick_params(rotation='auto')
Example #27
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_theta_limits(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r theta_mins = np.arange(15.0, 361.0, 90.0) theta_maxs = np.arange(50.0, 361.0, 90.0) DIRECTIONS = ('out', 'in', 'inout') fig, axes = plt.subplots(len(theta_mins), len(theta_maxs), subplot_kw={'polar': True}, figsize=(8, 6)) for i, start in enumerate(theta_mins): for j, end in enumerate(theta_maxs): ax = axes[i, j] ax.plot(theta, r) if start < end: ax.set_thetamin(start) ax.set_thetamax(end) else: # Plot with clockwise orientation instead. ax.set_thetamin(end) ax.set_thetamax(start) ax.set_theta_direction('clockwise') ax.tick_params(tick1On=True, tick2On=True, direction=DIRECTIONS[i % len(DIRECTIONS)], rotation='auto') ax.yaxis.set_tick_params(label2On=True, rotation='auto')
Example #28
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_polar_gridlines(): fig = plt.figure() ax = fig.add_subplot(111, polar=True) # make all major grid lines lighter, only x grid lines set in 2.1.0 ax.grid(alpha=0.2) # hide y tick labels, no effect in 2.1.0 plt.setp(ax.yaxis.get_ticklabels(), visible=False) fig.canvas.draw() assert ax.xaxis.majorTicks[0].gridline.get_alpha() == .2 assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2
Example #29
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_polar_rorigin(): r = np.arange(0, 3.0, 0.01) theta = 2*np.pi*r fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.plot(theta, r) ax.set_rmax(2.0) ax.set_rmin(0.5) ax.set_rorigin(0.0)
Example #30
Source File: test_axes.py From neural-network-animation with MIT License | 5 votes |
def test_polar_annotations(): # you can specify the xypoint and the xytext in different # positions and coordinate systems, and optionally turn on a # connecting line and mark the point with a marker. Annotations # work on polar axes too. In the example below, the xy point is # in native coordinates (xycoords defaults to 'data'). For a # polar axes, this is in (theta, radius) space. The text in this # example is placed in the fractional figure coordinate system. # Text keyword args like horizontal and vertical alignment are # respected # Setup some data r = np.arange(0.0, 1.0, 0.001) theta = 2.0 * 2.0 * np.pi * r fig = plt.figure() ax = fig.add_subplot(111, polar=True) line, = ax.plot(theta, r, color='#ee8d18', lw=3) line, = ax.plot((0, 0), (0, 1), color="#0000ff", lw=1) ind = 800 thisr, thistheta = r[ind], theta[ind] ax.plot([thistheta], [thisr], 'o') ax.annotate('a polar annotation', xy=(thistheta, thisr), # theta, radius xytext=(0.05, 0.05), # fraction, fraction textcoords='figure fraction', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='left', verticalalignment='baseline', )