Trouble Plotting Multiple Data Sets on Same Graph

UPDATE: I needed to convert my density (rho) from g/cm^3 to kg/m^3 to become significant. Thanks for the help, all.
I'm trying to plot a data set and an equation on the same figure, and for some reason the equation keeps coming up as just a straight line. When I separate the two, though, the equation plots perfectly. Can someone help me, please? Here's my code:
if true
% mew=0.8; % 0.6 to 0.1
lam=0.9; % 0.4 to 0.9
rho=2.7; % average crustal density in g/cm^3
D=12; % 15 km to 10 km
x=(-20e3:100:20e3); % in m
V=9.5129e-10; % 3 cm/yr into m/s
tau=mew/(1+mew^2)*(1-lam)*rho*9.8*D; % from equation tau = u/(1+u^2) * omega
q=1e3*tau*V/pi*(1-x./D.*atan(D./x)); % in mW/m2
Obs=[
-18.2 78.892
-13.8 73.071
-11.2 74.65
-4.672 76.751
-4.262 75.056
-3.996 81.076
-3.1 83.86
-2.843 76.377
-0.165 76.931
0.267 82.343
0.684 83.022
0.736 82.221
0.893 78.375
1.732 75.687
1.785 75.569
3.785 78.503
4.155 74.037];
distance=Obs(:,1); % in km
heat=Obs(:,2); % in mW/m2
figure(1)
plot(x/1e3, q+73,'b', distance, heat, 'ko')
title ('SAF Heat Flow ')
xlabel ('Distance From Fault (km)')
ylabel('Heat Flow (mW/m^2)')
legend (['\mu = ', num2str(mew),' \lambda = ', num2str(lam), ' D= ',num2str(D/1e3)])
end

1 Comment

Look at the scale of q, it is very small. The data just looks flat try.
ylim([73,73.00001])
You could try scaling q to see more variation visually

Sign in to comment.

 Accepted Answer

I figured it out!! My density was in g/cm^3, but when I manipulated it to kg/m^3, it starts to better fit the curve. Thank you all for your help, I really appreciate it.

More Answers (1)

Alison - do you mean that
plot(x/1e3, q+73,'b')
plots perfectly? If I run your code, then yes, there is a spike at zero so I don't see a flat line. But you need to consider your q data. The minimum value is 5.6281e-13 and the maximum value is 4.6901e-06. These are very small numbers and when you add them to 73 then you are plotting values that are all close to 73.
When you plot just the above, then the y-axis ranges over such a small interval (look closely at it) that the spike at zero can easily be seen. But when you plot this with the other data, you don't get that granularity and so the spike is flattened. You would have to zoom in to see it.
Perhaps there is a problem with the q data. Can you confirm that it is as you expect?

2 Comments

I believe this is correct--my goal is to manipulate mew and lambda to fit the data provided, but i'm struggling as I'm not able to see the peak because the q values are so small/close to 73.
You could try plotting your data using two y-axes. See plotting with two y-axes for an example.
Or if you have an older version of MATLAB (like mine which does not have yyaxis), you can try using plotyy like
[hAxes] = plotyy(x/1e3, q+73, distance, heat)
% change the lifestyle for the second line
hLine2 = get(hAxes(2), 'Children');
set(hLine2,'LineStyle','o')
The above makes some assumptions (that there is at least two axes handles, and that there is only one child) so you may want to make some changes to make the code more robust.

Sign in to comment.

Categories

Find more on Graphics Object Properties 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!