Linear plot to contour plot
Mostra commenti meno recenti
Hello, I'm creating a temperature profile of a cylinder, and got a range of temperatures to different radiuses, like shown in the picture below. Kelvin on the y-axis and radius [m] on the x-axis.

So i did this with the plot(r,T) command, r-vector having the radius and T-vector my corresponding temperatures. Now, i want to make this into a contour plot, so i can see it like circle, to show it like a real cross-cut of my cylinder. (I know it might not be up to much practical use, but i want to learn how to do it)
I've tried to read about contourplots, meshgrids and so on, but just can't seem to figure out a way to do this. Could anyone explain me how to transform a line plot into a contour plot with circular level curves.
Risposta accettata
Più risposte (2)
Jürgen
il 18 Set 2012
0 voti
Hi,
to make a contour plot you need two dimensions, since you only have r the radius it won't work
You need the (x,y) coordinates of the cilinder or (r,angle) is you want to use polar coord. Then you could try a polar plot
once you have the coord in two dimensions use meshgrid en contour
regardsJ
1 Commento
Asger
il 18 Set 2012
I don't think a polar plot would do the trick, you could use patches:
data_length = 10;
%The values you want to plot:
your_vals = rand(data_length,1);
x = (0:data_length - 1)'; %Coordinates, gotta start somewhere
y = 0.*x;
coord_mat = [x y];
numColors = 64; %How many colors you want
color_array = autumn(numColors); %Colormap, could be something else
%Getting color index:
minVal = min(your_vals);
maxVal = max(your_vals);
your_idx = (your_vals - minVal) ./ (maxVal - minVal); %Linearly mapping the colormap
your_idx = round((numColors - 1) * your_idx + 1);
R = @(x)[cos(x) -sin(x); sin(x) cos(x)]; %Rotation matrix
numVals = 0;
newVec = [];
%Rotating your data, do less intervals if you want less patches
for ii = 0:pi/20:2*pi
newVec = [newVec;coord_mat*R(ii)];
numVals = numVals + 1;
end
%Cushioning so as not to get out of bounds
newVec = [newVec repmat(color_array(your_idx,:),numVals,1)];
newVec = [newVec ; newVec(1:data_length,:)];
numVals = numVals + 1;
%Patching
for ii = 1:numVals-1
for jj = 1:data_length-1
idx_vec = [(ii-1)*data_length + jj;...
(ii-1)*data_length + jj + 1;...
ii*data_length + jj + 1;...
ii*data_length + jj;...
];
p = patch('Faces',idx_vec','Vertices',newVec(:,[1 2]));
set(p,'FaceColor','interp',...
'FaceVertexCData',newVec(:, [3 4 5]),...
'EdgeColor','none')
hold on;
end
end
You could probably simplify the loop...
Or reduce the number of patches, e.g. patching circle sections
Categorie
Scopri di più su Contour Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!