Plotting Various Colors & Symbols
116 views (last 30 days)
Show older comments
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 Comments
Adam Danz
on 5 Jun 2020
"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.
Accepted Answer
Adam Danz
on 7 Jun 2020
Edited: Adam Danz
on 12 Jun 2020
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 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!