필터 지우기
필터 지우기

changing the scaling in the plot permenantly

조회 수: 4 (최근 30일)
fima v
fima v 2017년 2월 19일
편집: dpb 2017년 2월 20일
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

답변 (2개)

dpb
dpb 2017년 2월 19일
편집: dpb 2017년 2월 20일
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
Walter Roberson
Walter Roberson 2017년 2월 20일
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 2017년 2월 20일
"...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.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2017년 2월 19일
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.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by