Trying to increase marker size in scatter plot caused my plot and data to be replaced by a blank blue screen.

3 views (last 30 days)
Brittany Davis
Brittany Davis on 30 Nov 2021
Edited: DGM on 30 Nov 2021
I'm trying to plot a 2D (x,y), z response on a scatter plot. I had it working, but then wanted to change the size of the markers since they're a little small. I entered a few commands and nothing seemed to work because I got errors in the command window. Then all of a sudden my scatterplot was gone and replaced by a blank blue screen. No axes. Nothing. If i'm not in the range of my data, I get a white blank graph with x and y axes. I tried zooming out to see if perhaps I set my marker size to something huge...also no luck.
I have tried entering set(gcf, 'Renderer', 'painters') and set(gcf, 'Renderer', 'opengl') into the command window. Nothing changed.
I suspect I accidentally set something on my computer because I have two different versions of matlab on my laptop (student) and both are having this error.
T is an imported 258 x 5 excel file containing data points. This is my base code. I am using MATLAB R2020a and reran in R2020b to see if I had the same issue. Thanks.
clc
clear all
close all
% This code was made assuming a pitot tube would be used for tunnel readings
% 1. insert dat or xml file with tunnel test section wall data
% Note: Dynamic Pressure is Total - Static
T=readtable('TS specs.xlsx');
% 2. Plot data to determine where wall fluctuations are.
scatter(T.X,T.Y,T.Dynamic_Pressure,'MarkerFaceColor','flat')
xlabel('X Coordinate (mm)')
ylabel ('Y Coordinate (mm)')
title ('Dynamic Pressure along Axial ODU SST Tunnel Walls')
ylim([1e-3 12e-3]);
xlim([-0.017 -0.008]);
Pictures: All are after one run of my code.
  1. What pops up when I run my code.
2. I am able to click on a data point, but can't see it or others.
3. Outside out my data range limit I can see a blank plot with axes.
SOLVED.
For anyone else with the same issue, I updated my code to:
pointsize = 2;
scatter(T.X, T.Y, pointsize, T.Dynamic_Pressure);
cb=colorbar()
which has solved all of my issues. Benjamin's answer was correct. My plot was interpreting the third input as size. I now have a 2D plot with 3 vectors and a color gradient for the 3rd vector.
  2 Comments

Sign in to comment.

Accepted Answer

Benjamin
Benjamin on 30 Nov 2021
You are using T.Dynamic_Pressure as the marker size, right? Marker size is in units of points-squared. I have no idea what kind of values T.Dynamic_Pressure has, but is it possible that these values are large enough to create huge markers? You may try using T.Dynamic_Pressure/1000 or some other factor in your call to scatter so that the marker size is still proportional to T.Dynamic_Pressure without being numerically equal to it.
  3 Comments
Benjamin
Benjamin on 30 Nov 2021
scatter3 will give you a 3D plot, but you can set the axes View to make it look like a 2D plot, in which case, I'm not sure what the 3rd variable is for

Sign in to comment.

More Answers (1)

DGM
DGM on 30 Nov 2021
Edited: DGM on 30 Nov 2021
You're dealing with 2D data, so ideally you'd be using 3 dimensions to visualize it. That said, there are only 2 unique values for Y. This might suggest a simplification. You'll have to decide what's appropriate or meaningful.
T = readtable('TS specs.xlsx');
nl = size(T,1);
% do a 3D scatter plot
scatter3(T.X,T.Y,T.Dynamic_Pressure,'MarkerFaceColor','flat')
As you can see, the data forms two salient groups. A stacked 2D plot may suffice.
% split Y into two series using scatter
figure % reset web-plot
hold on
h1 = scatter(T.X(1:nl/2),T.Dynamic_Pressure(1:nl/2),'red','MarkerFaceColor','flat');
h2 = scatter(T.X(nl/2+1:end),T.Dynamic_Pressure(nl/2+1:end),'blue','MarkerFaceColor','flat');
legend([h1 h2],{sprintf('Y = %.5f',T.Y(1)) sprintf('Y = %.5f',T.Y(end))})
Since the data is ordered, it might be easier to read details with a simple line plot.
% split Y into two series using plot instead
figure % reset web-plot
hold on
h1 = plot(T.X(1:nl/2),T.Dynamic_Pressure(1:nl/2),'r');
h2 = plot(T.X(nl/2+1:end),T.Dynamic_Pressure(nl/2+1:end),'b');
legend([h1 h2],{sprintf('Y = %.5f',T.Y(1)) sprintf('Y = %.5f',T.Y(end))})
You'll have to add back the title and labels, etc.

Community Treasure Hunt

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

Start Hunting!

Translated by