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 Kommentare

Adam Danz
Adam Danz am 4 Jun. 2020
At what part of this process are you stuck?
Doug
Doug am 5 Jun. 2020
The whole process...I mean I can make subplots, but thats about it. No idea on how to do the separation based on D and grouping by AR, then the colors based on each AR and symbols based on each D, I have an idea on that, but its pretty weak.
Adam Danz
Adam Danz am 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.
Doug
Doug am 6 Jun. 2020
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.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Adam Danz
Adam Danz am 7 Jun. 2020
Bearbeitet: Adam Danz am 12 Jun. 2020

0 Stimmen

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 Kommentare

Doug
Doug am 8 Jun. 2020
Big thanks for the help Adam
Is there a way where I can seperate the 3 columns of subplots into their own figures?
Adam Danz
Adam Danz am 8 Jun. 2020
Bearbeitet: Adam Danz am 18 Jun. 2020
Sure,
  1. Put the figure() line inside the loop at the top.
  2. instead of looping 1:nGroups, loop 1:3
  3. Change each subplot(...) to subplot(1,3,i) or subplot(3,1,i)
  4. I think you'll need to change the titles, too.
If you get stuck on one of the steps, I'd be glad to help.
Doug
Doug am 9 Jun. 2020
Thanks again Adam.
I was thinking about the color situation, could I add a column at the end of the .mat file which has the rgb values and use that?
Cheers.
Adam Danz
Adam Danz am 9 Jun. 2020
If I remember correctly, D.AR defines the colors, is that right?
Instead of using plot(), you can use scatter() which allows you to change the color of each point.
Alternatively, you can continue to use plot() but you'll need to break up each segement of data based on color since you can only assign one color in plot().
I don't know what your RGB matrix looks like but you'll use the values in D.AR to map the rows of the matrix to the data.
Doug
Doug am 10 Jun. 2020
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 am 10 Jun. 2020
Could I see your updated code?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Doug
Doug am 11 Jun. 2020

0 Stimmen

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 Kommentare

Adam Danz
Adam Danz am 11 Jun. 2020
The symbols are different for each diameter. If you look at your subplots, each subplot has a different symbol and each subplot contains data from a different diameter.
Circles Diamonds Squares
The description from the question is,
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).
Is that still what you want to do?
Also, in the first subplot above there are 32 points but they all fall on 4 coordinates. Even if the colors are changed according to AR, you will only see the top 4 points. So I'm wondering if this is really the goal.
Doug
Doug am 12 Jun. 2020
Yes, I am still wanting to have the different colours and symbols on all plots.
I will most likely change the data for the firsst plot anyway, so no issues there.
Adam Danz
Adam Danz am 12 Jun. 2020
This is confusing. You wrote that you want each value of D to be a different symbol (that's clear) and that there should be 3 subplots, one for each D (that's clear) which would result in each subplot containing only 1 symbol. But then you said "I want to have the different colours and symbols on all plots" which is where I get lost because if each plot contains its own D value and the D value defines the symbol, then each subplot can only have 1 symbol.
Adam Danz
Adam Danz am 12 Jun. 2020
I've updated my answer with a demo you can follow that teaches you how to use the D and AR columns to specify marker and colors of each point. Study it and try to understand the logic that makes it work. Then you can adapt it to what you need to do.
Doug
Doug am 15 Jun. 2020
You are correct with my original wording being a bit off. Apolgies for that.
I will work through the demo and if I have any further questions I will let you know.
Thanks heaps for your help
Adam Danz
Adam Danz am 15 Jun. 2020
Sure! Let me know if you get stuck.
Doug
Doug am 30 Jun. 2020
Bearbeitet: Doug am 1 Jul. 2020
Adam,
I have gone a different route for the plotting, where everything is a bit more streamlined. I am now having an issue 1 portion of my plotting function...namely extracting the data from my results table.
See below for the code.
load RES_20200630.mat
[DGroup, DGroupID] = findgroups(RES.D);
[ARGroup,ARGroupID] = findgroups(RES.AR);
xvar = 'Fr_D'
yvar = 'R_F'
for jj = 1:3
% Loop through the 3 diameters
for colID = 1:10
xdat = RES.(xvar)(contains(RES.D,DGroupID{jj}) & RES.AR == str2double(ARGroupID{colID}));
ydat = RES.(yvar);
alldat = [xdat ydat];
figure(1);
if subp>0
subplot(2,2,colID)
end
scatter(alldat(:,1),alldat(:,2))%,markershapes{jj},'MarkerEdgeColor',markercolours{colId},'MarkerFaceColor',markercolours{colId})
hold on
figure(jj+1)
if subp>0
subplot(2,2,colID)
end
scatter(alldat(:,1),alldat(:,2))%,markershapes{jj},'MarkerEdgeColor',markercolours{colId},'MarkerFaceColor',markercolours{colId})
hold on
end
end
I am only working on the xdat issue atm, as it will apply to the ydat variable as well. The problem is that I am getting all the results, where as previously I am looking for only a select few, based on the D and AR.
I have tried using 'ismember' instead of contains, but that only allows for me to select data based on a single parameter (D).
You assistance on this issue would be appreciated.
Adam Danz
Adam Danz am 1 Jul. 2020
Bearbeitet: Adam Danz am 1 Jul. 2020
Lots of weird stuff going on in that line. Why use str2double when you're not working with strings? The curly brackets are also a problem. Curly brackets are for cell arrays but you're using them with matrices.
Try this.
xdat = RES.(xvar)(ismember(RES.D,DGroupID(jj)) & ismember(RES.AR, ARGroupID(colID)));
Doug
Doug am 1 Jul. 2020
Bearbeitet: Doug am 1 Jul. 2020
Yeah, sorry about that, I've been playing around with making the table into a structure to see if that would make it any easier.
I just tried what you sent through and got the following error
xdat = RES.(xvar)(ismember(RES.D,DGroupID(jj)) & ismember(RES.AR, ARGroupID(colID)));
Error using cell/ismember (line 34)
Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character vector.
EDIT: I have changed the code to
xdat = RES.(xvar)(ismember(RES.D,DGroupID{jj}) & ismember(RES.AR, ARGroupID{colID}));
This now works.
Thanks for your help.
Adam Danz
Adam Danz am 1 Jul. 2020
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 am 2 Jul. 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020a

Tags

Gefragt:

am 4 Jun. 2020

Kommentiert:

am 2 Jul. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by