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

18 views (last 30 days)
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 Comment
Benjamin Kraus
Benjamin Kraus on 22 May 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?

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 22 May 2018
Edited: Ameer Hamza on 22 May 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 Comments

Sign in to comment.

More Answers (1)

Benjamin Kraus
Benjamin Kraus on 22 May 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 Comment
Chris Park
Chris Park on 22 May 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)

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!