Azzera filtri
Azzera filtri

changing the scaling in the plot permenantly

2 visualizzazioni (ultimi 30 giorni)
fima v
fima v il 19 Feb 2017
Modificato: dpb il 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

Risposte (2)

dpb
dpb il 19 Feb 2017
Modificato: dpb il 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 Commenti
Walter Roberson
Walter Roberson il 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 il 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.

Accedi per commentare.


Walter Roberson
Walter Roberson il 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.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by