问题
I have my (example) data in the following format:
R_min R_max θ_min θ_min Zones
0 260 0 1.57 114
260 270 0 1.57 106
270 320 0 1.57 107
As you can see, I have "zones" (areas) that are created from R_min to R_max that sweep from theta_min to theta_max. Each row of data represents an area that I want to plot with a corresponding color based on the zone number. In this simple case, the data I show above would look like the following picture:
What plotting software should I use to accomplish this? I have been investigating the following options:
MATLAB. I am having trouble finding exactly what I need, but have found features like http://www.mathworks.com/help/symbolic/mupad_ref/plot-density.html?searchHighlight=plot%3A%3Adensity
Gnuplot. My issue with Gnuplot is the lack of documentation.
Are there other programs or a better way to compile my data to make my task-at-hand doable?
My real data set has thousands of rows of data and not nearly as simple as a quarter circle rainbow.
回答1:
Here is one possible solution with gnuplot. That uses the circles
plotting style to draw the overlapping wedges at the origin with a specified radius. That requires you to have your data sorted by descending maximum radius, and that you have no gaps.
Here is a possible script:
set xrange [0:350]
set yrange [0:350]
set size ratio -1
set style fill solid noborder
set palette defined (106 'blue', 107 'yellow', 114 'magenta')
set cbrange [106:114]
unset colorbox
plot 'test.txt' using (0):(0):2:($3*180/pi):($4*180/pi):5 with circles linecolor palette notitle
with the result (with 4.6.4):
Some more remarks:
The radius of the circles is given in units of the x-axis, but the y-axis isn't adapted accordingly. That's why you must set both
xrange
,yrange
and even the ratio of the two axes withset size ratio -1
.Using the palette for coloring is one option, other options like using
linecolor variable
orlinecolor rgb variable
, are explained e.g. in gnuplot candlestick red and green fill.On Unix systems, the sorting could also be done on-the-fly with e.g.
plot '< sort -r test.txt' ...
回答2:
It's actually easy to do that with Matlab using simple trigonometry and the fill function:
% R_min R_max θ_min θ_min Zones
data = [
0 260 0 1.57 114
260 270 0 1.57 106
270 320 0 1.57 107];
% Define a color table, indexed by the "Zones" column
colors = {};
colors{114} = [1.0 0.0 0.5];
colors{106} = [0.7 0.0 1.0];
colors{107} = [1.0 1.0 0.0];
% Define the resolution of the plot (more points = more round)
nPoints = 100;
clf;
hold on;
for i = 1:size(data, 1)
% Extract the data from the i'th row. There's no need for this, you
% could access it directly below, but it makes the code more clean. :)
r_min = data(i,1);
r_max = data(i,2);
theta_min = data(i,3);
theta_max = data(i,4);
color = data(i, 5);
% First, get the sine and cosine between theta_min and theta_max
sin_theta = sin(linspace(theta_min, theta_max, nPoints));
cos_theta = cos(linspace(theta_min, theta_max, nPoints));
% Now, draw a semi-circle with radius = r_min and merge this
% semi-circle with another with radius = r_max, but reversed, so that
% it begins where the previous semi-circle ended.
x = [sin_theta * r_min sin_theta(end:-1:1) * r_max];
y = [cos_theta * r_min cos_theta(end:-1:1) * r_max];
% Draw the polygon.
fill(x,y, colors{color}, 'EdgeColor', colors{color});
end
hold off;
axis equal;
grid;
maxRadius = max(data(:,2));
axis([-maxRadius maxRadius -maxRadius maxRadius]);
Result:
来源:https://stackoverflow.com/questions/23331119/what-plotting-software-to-use-2d-polar-plot-with-unique-data