How do I make my bar3h work as intended?

1 visualización (últimos 30 días)
Jack Baker
Jack Baker el 19 de Feb. de 2021
Comentada: Jack Baker el 20 de Feb. de 2021
Hi,
I'm trying to make a bar3h graph(?) of flow rate data of air through a rectangular tube. I am able to make a contourf graph(?) that has correct color scaling. However when I try using bar3h it scales the colours off of the wrong numbers. I'd also like to fix the axis as they're supposed to go up in 0.02 increments for the x axis and 0.0183 increments for the z axis (with the y axis being the bars representing the flow rate of air).
bar3h(m6, 1)
f = colorbar();
f.Label.String = 'Velocity (m/s)';
caxis([0 17])
title('Contour plot of flow in the pitot tube at medium motor power (463W)');
grid on;
xlabel('Horizontal distance from the left wall (m)');
ylabel('Vertical distance from the top wall (m)');
I've attached the workspace matrices

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 20 de Feb. de 2021
Editada: Cris LaPierre el 20 de Feb. de 2021
A bar plot colors by series, not by height of the bar. If you remove the caxis command, you will see the colors correspond to the X location of the series; 1,2,3,4 or 5.
You can specify your own Z values using this syntax:
bar3h(Z,Y)
You can set your X tick labels using xticklabels
xticklabels(string(X(1:length(m6))));
So I don't have a solution for your desired coloring, but otherwise, try this code (uses your variables X and Y).
load 'Pitot tube contour workspace.mat'
bar3h(Y(1:length(m6)),m6)
xticklabels(string(X(1:length(m6))));
f = colorbar();
f.Label.String = 'Velocity (m/s)';
title('Contour plot of flow in the pitot tube at medium motor power (463W)');
grid on;
xlabel('Horizontal distance from the left wall (m)');
ylabel('Vertical distance from the top wall (m)');
  2 comentarios
Cris LaPierre
Cris LaPierre el 20 de Feb. de 2021
You might find this example of interest. Basically, it shows how to loop through each bar and change its color property. Perhaps this is more like what you wanted?
load 'Pitot tube contour workspace.mat'
b = bar3h(Y(1:length(m6)),m6);
xticklabels(string(X(1:length(m6))));
% Loop through each bar and set color equal to YData
for k = 1:length(b)
ydata = b(k).YData;
b(k).CData = ydata;
b(k).FaceColor = 'interp';
end
f = colorbar();
f.Label.String = 'Velocity (m/s)';
caxis([0 17])
title('Contour plot of flow in the pitot tube at medium motor power (463W)');
grid on;
xlabel('Horizontal distance from the left wall (m)');
ylabel('Vertical distance from the top wall (m)');
Jack Baker
Jack Baker el 20 de Feb. de 2021
Thank you so much! You're a lifesaver!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by