フィルターのクリア

could anyone tell me how to have equal spacing of selected numbers with respect to axis.

26 ビュー (過去 30 日間)
could anyone tell me how to have equal spacing of selected numbers with respect to axis with respect to the command line
set(gca, 'XTick', [0, 1, 2, 23,24]);
I want to have equal spacing between 0,1,2,23 and 24 with respect to x axis.
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 28 日
The data you are plotting, are the x values for it only 0, 1, 2, 23 and 24, and nothing else?
Is it necessary that the data cursor should show the 24 when it is over information in that range, or is it okay if the data cursor can be wrong?
... And you are still using R2015b, right?
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 29 日
s i am using R2015b. data cursor should show only 0,1,2,23,24 numbers in the x axis with equal spacing.
I want to have the graph by using the code
%before plotting
XData(XData>2&XData<23)=(XData(XData>2&XData<23)-2)/(23-2)+2;
XData(XData>=23)=XData(XData>=23)-(23-2)+1;
%plotting code
plot(XData,YData)
%renaming of ticks
set(gca, 'XTick', [0, 1, 2, 3,4]);
set(gca,'XTickLabel',num2str([0;1;2;23;24]))
If i use the code the number 0,23 and 24 are not getting displayed.

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 29 日
tx = XData;
mask = tx > 2.5;
tx(mask) = tx(mask) - 20;
plot(tx, YData);
xlim([0 4]);
set(gca, 'XTick', [0, 1, 2, 3,4]);
set(gca,'XTickLabel',num2str([0;1;2;23;24]))
dcm = datacursormode(gcf, 'DisplayStyle', 'datatip', 'UpdateFcn', @myupdatefcn, 'SnapToDataVertex', 'on');
with
function txt = myupdatefcn(src, event)
loc = event.Position;
x = loc(1);
y = loc(2);
if x > 2.5; x = x + 20; end
txt = {sprintf('x: %g', x), sprintf('y: %g', y)};
The assignment to dcm and the function are not needed if you do not care about what data cursor mode (tooltips) shows.
  3 件のコメント
Image Analyst
Image Analyst 2018 年 3 月 29 日
編集済み: Image Analyst 2018 年 3 月 29 日
Make it easy for us to see by using the green and brown frame icon to insert a picture/screenshot. Or else attach a PNG image instead of a .fig file, which takes multiple additional steps to see.
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 29 日
ok.I have attached the png format.

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

その他の回答 (2 件)

Sergey Kasyanov
Sergey Kasyanov 2018 年 3 月 28 日
You can compress data between 2 and 23 ticks roughly by
%before plotting
XData(XData>2&XData<23)=(XData(XData>2&XData<23)-2)/(23-2)+2;
XData(XData>=23)=XData(XData>=23)-(23-2)+1;
%plotting code
plot(XData,YData)
%renaming of ticks
set(gca, 'XTick', [0, 1, 2, 3,4]);
set(gca,'XTickLabel',num2str([0;1;2;23;24]))
  9 件のコメント
Sergey Kasyanov
Sergey Kasyanov 2018 年 3 月 29 日
Also you can use command
xlim([0,24])
to strech axis.
Prabha Kumaresan
Prabha Kumaresan 2018 年 3 月 29 日
i am using the code
XData(XData>2&XData<23)=(XData(XData>2&XData<23)-2)/(23-2)+2;
XData(XData>=23)=XData(XData>=23)-(23-2)+1;
plot(XData,YData)
xlim([0,24])
set(gca, 'XTick', [0, 1, 2, 3,4]);
set(gca,'XTickLabel',{'0','1','2','23','24'})
and the graph which i am getting is also attached.
It is seen from the graph all the points 0,1,2,23,24 are present at one side of the graph.The rest of the places are left blank.But I want to have even spreading of the numbers with equal spacing.

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


Image Analyst
Image Analyst 2018 年 3 月 29 日
Try this to find File Exchange submissions that allow a "break" in the axes: https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=broken+axis

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by