Unable to reverse the order of numbers on the Y-axis

19 Ansichten (letzte 30 Tage)
Chris Park
Chris Park am 22 Mai 2018
Kommentiert: Ameer Hamza am 22 Mai 2018
plot(1,a)
bar3c(flipud(dam_tot(:,:,a)))
colorbar;
colormap(jet);
caxis([0 0.1]);
set(gca,'XTick',[1:1:11]);
set(gca,'XTickLabels',round((minSpeedRef:speed_range/(resolution-1):maxSpeedRef)));
xtickangle(-45)
set(gca,'YTick',[1:1:11]);
ax.YDir = 'reverse';
set(gca,'YTickLabels',round(flipud((minTorqueRef:torque_range/(resolution-1):maxTorqueRef))));
ytickangle(45)
xlabel('Speed');
ylabel('Torque');
title(strcat(fname{a},' Damage per Load Case'),'fontsize',14);
set(gcf,'units','inches','position',[0 .5 7 5.5])
set(gca,'FontSize',12)
  1 Kommentar
Benjamin Kraus
Benjamin Kraus am 22 Mai 2018
I can't run your code without knowing more about a and dam_tot (and other variables). Setting YDir to reverse should flip the order of the numbers on the Y-axis. Can you post a screenshot of what you are seeing, and why it doesn't match what you are trying to get?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 22 Mai 2018
Bearbeitet: Ameer Hamza am 22 Mai 2018
Your line
ax.YDir = 'reverse';
is not actually doing what you think it is doing. You should add the following line before it.
ax = gca;
ax.YDir = 'reverse';
or use set()
set(gca, 'YDir', 'reverse');
Your code is not giving an error because it is a valid MATLAB syntax. It creates a new struct object with field YDir.
  9 Kommentare
Chris Park
Chris Park am 22 Mai 2018
Got it! Thank you!
Ameer Hamza
Ameer Hamza am 22 Mai 2018
You are welcome.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Benjamin Kraus
Benjamin Kraus am 22 Mai 2018
Without being able to run your code this is just speculation, but it looks like you may be double-flipping your Y-axis tick labels. Two lines of code stick out:
ax.YDir = 'reverse';
set(gca,'YTickLabels',round(flipud((minTorqueRef:torque_range/(resolution-1):maxTorqueRef))));
You have flipud in the call to set the YTickLabels, which may mean you are assigning the wrong tick labels to each tick (essentially assigning them in reverse order). Try commenting out the second line (the one that is setting YTickLabels) and see if it looks like the ticks are in the correct order. If so, remove the flipud.
  1 Kommentar
Chris Park
Chris Park am 22 Mai 2018
I tried comment out the line you recommended but it did not work. I have attached an image of the graph I am getting. I would like to reverse the order of the y-axis numbers (torque)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by