Unable to reverse the order of numbers on the Y-axis
18 views (last 30 days)
Show older comments
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
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?
Accepted Answer
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
More Answers (1)
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.
See Also
Categories
Find more on Colormaps 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!