フィルターのクリア

Axis interval of scatter plot

3 ビュー (過去 30 日間)
wesleynotwise
wesleynotwise 2017 年 6 月 15 日
編集済み: dpb 2017 年 6 月 16 日
Is there a more intelligent method to specify the interval of the axis of a scatter plot?
fig1 = gscatter(x,y, 'k', '.')
ylim([-20 20]);
yticks([-20 -15 -10 -5 0 5 10 15 20]); % this works but I am looking for a better code
set(fig1, 'ytick', [-20:5:20]); % something like this?

採用された回答

dpb
dpb 2017 年 6 月 15 日
Except ticks are property of the axes and gscatter as other plotting routines returns handle(s) to the object(s) it creates, not to the parent axes in which they're drawn.
If you didn't save the handle of the axes when you began, now's a good time to grab it...
hAx=gca; % get the handle of current axes and store it so can ensure using correct one later
set(hAx, 'ytick', [-20:5:20]);
With the new HG2 interface there's "dot" notation to get to the properties that can be a little friendlier some think than set but there are more sophisticated things one can do with set when dealing with multiple objects/values that make it useful to know and that the dot notation can't do. This isn't one of those cases, just commenting...
  2 件のコメント
wesleynotwise
wesleynotwise 2017 年 6 月 16 日
Alright, 'gca' is the answer! Thank you so much.
Also, what is HG2?
dpb
dpb 2017 年 6 月 16 日
編集済み: dpb 2017 年 6 月 16 日
No problem, glad to help...keeping handles to things is, in general, good practice.
"what is HG2?"
Shorthand for "Handle Graphics II", the updated version introduced with R2014b. It's markedly different underneath and has quite a few things that are incompatible with HG1 (aka HG "Classic") although the most top-level syntax is retained. <R2014b Graphics> has the details although you don't really need to know all that, just that it exists and there are differences that can be important particularly if interact with folks with earlier releases some things of each vintage will just not work with the other.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by