Clear Filters
Clear Filters

changing the scaling in the plot permenantly

2 views (last 30 days)
fima v
fima v on 19 Feb 2017
Edited: dpb on 20 Feb 2017
Hello, when i plot a graph each time i manually have to change the axes scaling ,so it will show not every 5 [0,5,10] but each one [0,1,2,3,4,5,6,7,8,9,10] how can i control that with a command?
thanks

Answers (2)

dpb
dpb on 19 Feb 2017
Edited: dpb on 20 Feb 2017
set(gca,'xtick',[0:10])
programmatically isn't that bad; could wrap into a user function if doing this a lot. If you make this default, that could get really, really, really annoying quickly I'd think. But, it's doable that way, too...
set(groot,'defaultAxesXLim', [0 10],'defaultAxesXLimMode','manual', ...
'defaultAxesXTick',[0:10],'defaultAxesXTickMode','manual')
See section on Default Values for Automatically Calculated Properties in documentation under "Graphics Objects" heading.
ADDENDUM Per part of Walters objections, edit'ed for brevity altho I still think if going to do this should set both limits and ticks to coincide until change them programmatically, and that it is a_bad_idea (tm).
ADDENDUM 2
In an effort for both worlds, a minimal implementation of the first idea above would look something like--
function hL=rngeplot(varargin)
% plot with cause tick marks always at 0:10
hL=plot(varargin{:});
set(gca,'ylim',[0 10],'ytick',[0:10])
Application of this would be just like plot excepting it would cause the tick marks to end up at 0:10 irrespective as requested. BUT, it would not change default behavior of Matlab thus requiring modifying startup.m and restarting to revert to "normal" behavior.
Trivial example--
subplot(2,1,1)
rngeplot(1:20,1:20)
subplot(2,1,2)
rngeplot(1:20,1:20,'r:x','linewidth',2,'markersize',10)
yields
which shows besides default x,y data, the ability to use the optional styles and/or named parameters isn't lost.
With only a modicum of additional effort, one could build the function such that could also pass in a range vector which would make it much more versatile.
Walter thinks I "preach" too much, but I'd submit something like the above is the better solution by far. Advice can be accepted/rejected at will, of course.... :)
NB: I did set the range as well as the ticks to at least keep them in synch; without that, strange things to explain can easily occur...
  4 Comments
Walter Roberson
Walter Roberson on 20 Feb 2017
The xtick mode manual means the ticks are not going to change as the axes is rescaled. The ticks are also not going to change as the xlim is changed, such as if data for a completely different range is plotted or such as if the user uses the interactive tools to pan the plot.
Permanently is permanently. I certainly would not do this myself. But I have been given to understand by some that only bad teachers give people the answers they need instead of the answer they asked for.
dpb
dpb on 20 Feb 2017
"...only bad teachers give people the answers they need instead of the answer they asked for."
That's a new concept to me...and think this dog is too old for a new trick! :)
If that were the rule here, we'd be teaching how to poof variables into the workplace as one of if not the primary topic.

Sign in to comment.


Walter Roberson
Walter Roberson on 19 Feb 2017
In your startup.m file, add the line
set(0, 'DefaultAxesXTick', 0:10, 'DefaultAxesXTickMode', 'manual');
Then exit MATLAB and re-enter MATLAB.
This will affect all plots from that point onward that do not create their own X ticks.

Categories

Find more on 2-D and 3-D Plots 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!