Trying to increase marker size in scatter plot caused my plot and data to be replaced by a blank blue screen.
조회 수: 96 (최근 30일)
이전 댓글 표시
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.
- 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
DGM
2021년 11월 30일
Can you attach the data or a snippet of it so that the issue can be reproduced. Obviously, I can throw together placeholder data, but that doesn't exactly prove anything, since the scaling is unknown and possibly relevant.
scatter(rand(1,30),rand(1,30),100*rand(1,30),'MarkerFaceColor','flat')
xlabel('X Coordinate (mm)')
ylabel ('Y Coordinate (mm)')
title ('Dynamic Pressure along Axial ODU SST Tunnel Walls')
채택된 답변
Voss
2021년 11월 30일
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
Voss
2021년 11월 30일
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
추가 답변 (1개)
DGM
2021년 11월 30일
편집: DGM
2021년 11월 30일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!