www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/CustomizePolarAxesGridLinesAndAppearanceExample.m
%% Customize Polar Axes Grid Lines and Appearance % You can modify certain aspects of polar axes in order to make the chart % more readable. For example, you can change the grid line locations and % associated labels. You also can change the grid line colors and label % font size. %% Create Polar Plot % Plot a line in polar coordinates and add a title. theta = linspace(0,2*pi); rho = 2*theta; figure polarplot(theta,rho) title('My Polar Plot') %% Change _theta_-Axis Grid Line Locations and Units % Display grid lines along the _theta_-axis every 45 degrees. Specify the % grid line locations as a vector of increasing values. thetaticks(0:45:315) %% % Label the _theta_-axis values in radians instead of degrees by % changing the |ThetaAxisUnits| property of the polar axes object. Use % |gca| to assign the polar axes object to the variable |pax| in order to % access its properties. pax = gca; pax.ThetaAxisUnits = 'radians'; %% Rotate _theta_-Axis and Reverse Direction % Change the angles to increase in a clockwise direction. Also, % rotate the _theta_-axis so that the zero reference angle is on the left % side. pax = gca; pax.ThetaDir = 'clockwise'; pax.ThetaZeroLocation = 'left'; %% Change _r_-Axis Limits, Grid Line Locations, and Labels % Change the limits of the _r_-axis so that the values range from -5 to 15. % Display grid lines at the values -2, 3, 9, and 15. Then, change the % labels that appear next to each grid line. Specify the labels as a cell % array of character vectors. rlim([-5 15]) rticks([-2 3 9 15]) rticklabels({'r = -2','r = 3','r = 9','r = 15'}) %% Change Polar Axes Font Size % Change the font size for the polar axes labels. pax = gca; pax.FontSize = 12; %% Change Polar Axes Colors and Line Width % Use different colors for the _theta_-axis and _r_-axis grid lines and % associated labels by setting the |ThetaColor| and |RColor| properties. % Change the width of the grid lines by setting the |LineWidth| property. % % Specify the colors using either a character vector of a color % name, such as |'blue'|, or an RGB triplet. An RGB triplet is a % three-element row vector whose elements specify the intensities of the % red, green, and blue components of the color. The intensities must be in % the range [0,1], for example, [0.4 0.6 0.7]. pax = gca; pax.ThetaColor = 'blue'; pax.RColor = [0 .5 0]; pax.LineWidth = 2; %% % Change the color of the all the grid lines without affecting the labels % by setting the |GridColor| property. pax.GridColor = 'red'; %% % When you specify the |GridColor| property, the |ThetaColor| and |RColor| % properties no longer affect the grid lines. If you want the |ThetaColor| % and |RColor| properties to affect the grid lines, then set the % |GridColorMode| property back to |'auto'|.