Plotting Various Colors & Symbols

92 次查看(过去 30 天)
Hello,
I need help with the attached .mat file.
I am looking to make a series of 4 subplots for each D (Column 1) where each D is a different Symbol, and with that a different Color for each AR (Column 2). Each plot should look something similar to that of the attached Figure (Example_1).
After all the subplots I then need an additional plot at the end where I have all the data presented for 1 subplot for each D (Example_2).
Thanks in advance for the assistance.
  4 个评论
Adam Danz
Adam Danz 2020-6-5
"I am looking to make a series of 4 subplots for each D"
There are only 3 unique RES.D values in your data so it's very unclear how to create 4 subplots from that.
You mention a time series. I dont' see any obvious time values in your table. It's clear the the D column defines the symbol and the AR column defines the color but you haven't described which column contains the data you're plotting.
Doug
Doug 2020-6-6
Apologies.
I'm looking for a series of subplots for each D. So one series of subplots for D = 48.3, one for D = 80, and one for D = 101.6. For each series of subplots its doesn't matter about which columns require plotting at this moment, just getting it setup to do say 4 subplots of the remaining data for each D.
Example:
Figure 1: D = 48.3
subplot 1 -> Re vs Fr_D
subplot 2 -> Re vs R_F
subplot 3 -> V vs R_F
etc.
Figure 2 is the same but for D = 80, and so on.
Hope this helps.

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-6-7
编辑:Adam Danz 2020-6-12
This should get you started. You can tweek it to meet your needs and leave a comment if you have any problems.
It creates 1 figure with 3x3 subplots. You can easily create 3 figures with 1x3 or 2x2 subplots if you'd like.
load('RES_20200604_1215.mat')
[dGroup, dGroupID] = findgroups(RES.D);
nGroups = numel(dGroupID);
figure()
for i = 1:nGroups
idx = dGroup==i;
subplot(nGroups,3,(i-1)*3+1)
plot(RES.Re(idx), RES.Fr_D(idx), 'o');
xlabel('Re', 'interpreter', 'none');
ylabel('Fr_D', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
subplot(nGroups,3,(i-1)*3+2)
plot(RES.Re(idx), RES.R_F(idx), 'd');
xlabel('Re', 'interpreter', 'none');
ylabel('R_F', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
subplot(nGroups,3,(i-1)*3+3)
plot(RES.V(idx), RES.R_F(idx), 's');
xlabel('V', 'interpreter', 'none');
ylabel('R_F', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
end
General demo: Scatter plot with different colors and symbols
This demo uses your RES table. The "D" column defines the symbols and the "AR" column defines the colors. The x and y axes are "Re" and "R_F" values respectively.
Read the comments to understand the big-picture purpose of each line/section. If there's a function you're unfamiliar with, look it up in the documentation to understand its inputs and what it's doing.
The main idea is that each row of your table is assigned a different symbol based on D and a different color based on AR. The scatter() function can specify the color of each point but it can only plot one marker type at a time. So the rows of your table are plotted in a loop in groups of marker-type.
% Group rows by D-value
[dGroup, dGroupID] = findgroups(RES.D);
% Define a bunch of symbols but you'll only use 'n' of them where n is the number of values in dGroupID.
symbs = {'o' 's' 'd' 'p' '*' '^' 'v' '<' '>'};
% Group rows by AR value
[arGroup, arGroupID] = findgroups(RES.AR);
% Define m colors where m is the number of values in arGroupID.
% I'm using the jet() colormap; see the documentation for other colormaps.
colors = jet(numel(arGroupID));
rowColors = colors(arGroup,:); %<-- color of each row
% Create figure
fig = figure();
ax = axes(fig);
hold(ax, 'on')
% Plot R_F as a function of Re
% Loop through each D group
h = gobjects(size(dGroupID));
for i = 1:numel(dGroupID)
% Match the rows that belong to the current D group
idx = dGroup == i;
% Plot all values that belong to current AR group
scatter(ax, RES.Re(idx), RES.R_F(idx), 50, rowColors(idx,:),symbs{i},'filled')
% Create "dummy markers" that will not appear in the plot but will appear in the legend
% DisplayName sets up the legend strings
h(i) = plot(nan, nan, 'k', 'Marker', symbs{i}, 'LineStyle', 'none', 'DisplayName', sprintf('D = %.1f', dGroupID(i)));
end
legend(h,'Location', 'NorthWest')
% Add colorbar, make sure the axis colormap is set to the colormap you used in the scatter plot
colormap(ax, colors)
cb = colorbar(ax);
% Set range of colormap values to AR values
caxis([min(arGroupID), max(arGroupID)])
% Label colorbar
ylabel(cb, 'AR values')
  6 个评论
Doug
Doug 2020-6-10
Yes, you are correct that D.AR dictates the colour.
I'll go with scatter, as you suggest it is easier to change the colours of points this way.
I could go with an RGB triplet for the matrix, but I am open to suggestions.
Back to your previoous comment regarding changing each subplot to "subplot(1,3,i) or subplot(3,1,i)", neither of these options output all 3 subplots in each figure, it is sometimes only providing 1 subplot.
Adam Danz
Adam Danz 2020-6-10
Could I see your updated code?

请先登录,再进行评论。

更多回答(1 个)

Doug
Doug 2020-6-11
Adam see below for the code.
Another thing is that the symbols are not different for each diameter.
I have also attached an updated .mat file where the colours are in the last column in Hex format
[dGroup, dGroupID] = findgroups(RES.D);
nGroups = numel(dGroupID);
for i = 1:3
figure()
idx = dGroup==i;
subplot(1,3,i)
scatter(RES.Re(idx), RES.Fr_D(idx), 'o');
xlabel('Re', 'interpreter', 'none');
ylabel('Fr_D', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
subplot(1,3,i)
scatter(RES.Re(idx), RES.R_F(idx), 'd');
xlabel('Re', 'interpreter', 'none');
ylabel('R_F', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
subplot(1,3,i)
scatter(RES.V(idx), RES.R_F(idx), 's');
xlabel('V', 'interpreter', 'none');
ylabel('R_F', 'interpreter', 'none');
title(sprintf('D = %.2f', dGroupID(i)));
end
  11 个评论
Adam Danz
Adam Danz 2020-7-1
Your data must be different than the data provided 3 comments above because the parentheses worked for me. Glad you worked it out! :)
Doug
Doug 2020-7-2
Whoops, I had changed the 'findgroups' to cells, instead of leaving them as they were. Oh well...it still works.
Thanks heaps for your help with this, it is much appreciated.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by