MATLAB Answers

Weird plot axis range and ticks

9 views (last 30 days)
Meva on 12 Oct 2016
Commented: Star Strider on 16 Oct 2016
Just a quick question, I intended to compare numerical solutions and analytical solutions of a system. I plot them. But, the y-axis range is suspicious. Please see below plot.
Do you have any idea why Matlab doing this. I guess, the difference between two axis ticks is smaller than 10^(-4), that is why it did not include those 10^(-4) part. Am I right?

  1 Comment

Meva on 12 Oct 2016
Okay I found an answer. Basically, I need to add
set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%d'))
But now, my y-axis ticks look like
But I don't like this appearance. Is it possible to use
notation or
decimal notation
instead of
Also, how can I get rid of
two zeros
terms in y-axis ticks..

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 Oct 2016
It probably is. Instead of num2str, use sprintf.
Experiment with the format descriptor string to get the result you want.


Show 6 older comments
Star Strider
Star Strider on 13 Oct 2016
If none of your tick labels have exponents, one quick fix is simply to replace the ‘ytixstr’ assignment with:
ytkstr = sprintf('%.5f\n', ytix_mnt); % Create Strings For Y-Labels, Choose Mantissa Format As: '%.5f'
If some do and others don’t, the code quickly gets very complicated. It’s not something I want to write just now.
Meva on 16 Oct 2016
I do appreciate your nice tips @Star Strider. This works.
Star Strider
Star Strider on 16 Oct 2016
As always, my pleasure.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Translated by