how to modify the axis labels in the attached plot?

조회 수: 19 (최근 30일)
blues
blues 2020년 9월 16일
댓글: Walter Roberson 2020년 9월 16일
clc; close all; workspace
coinci = load('Coinc_600_MBq.dat');
Y = coinci(:,1); % angle in radian (0 - 360) values
X = coinci(:,2);
% 2D histogram with 321 bins for X and 641 bins for Y (1 bin = 1mm)
hist_rebin = hist3([Y, X], 'Nbins', [321 641]);
figure(1)
imshow(hist_rebin, []);
xlabel('S'); ylabel('T');
title('');
colormap gray; axis on;
% Output of this plot is attached.
% Now, I want to make a plot with X-labels as:
% '-320','-200','-100','0','100','200','320'.
% To do this, I need to change my bin 641/2 (middle value) as zero, lowest bin as (641-1)/2 as -320 and
% highest bin as (641-1)/2 as 320 as shown in plot by using red color. How to do this?
% Similarly, I want to change radians in y-labels to angles in terms of pi.
% Finally, I want to see the following as the ticks values in my plot:
%xticks([-320 -200 -100 0 100 200 320])
%yticks([pi/2 pi/4 0 pi -pi/4 pi/2])
%xticklabels({'-320','-200','-100','0','100','200','320'})
%yticks(['{\pi}/2', '{\pi}/4', '0', '-{\pi}/4', '-{\pi}/2'])
%How can I do this? Any help is appreciated.

답변 (2개)

Walter Roberson
Walter Roberson 2020년 9월 16일
편집: Walter Roberson 2020년 9월 16일
imshow(hist_rebin, []);
You would change that. Add in the 'XData' and 'YData' options telling imshow where to position the image in data units.
Caution: XData and YData give the coordinates for the centers of the corner pixels in data units. You need to think about whether you want -320 exactly to be the left edge of the image, or if you want -320 exactly to point to the center of the left pixel. Is there data "at" -320, or is -320 where the data "begins" ?
  댓글 수: 2
blues
blues 2020년 9월 16일
Thank you for this neat trick.
imshow(hist_rebin, [], 'XData', [-320 320], 'YData', [-pi/2 pi/2]);
It worked in X-axis but not in Y-axis. My data is in radians, so I am suposed to convert radians to degree to use this 'YData', [-pi/2 pi/2]?
Walter Roberson
Walter Roberson 2020년 9월 16일
No, you do not need to convert to degrees.
However, you should take into account that when you imshow(), unless "hold on" is in effect, imshow() automatically sets the axes YDir to reverse so that the entries with the lowest row number appear at the top of the display.

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


Star Strider
Star Strider 2020년 9월 16일
I could not get the axis tick labels to show with imshow, so I went with image instead (and a bit of manual editing to import the image):
hist_rebin = imread('1how to modify the axis labels in the attached plot - 2020 09 16.png');
figure
image(hist_rebin)
xlabel('S')
ylabel('T')
Ax = gca;
Ax.TickLabelInterpreter = 'latex';
xt = Ax.XTick;
xtl = {'-320','-200','-100','0','100','200','320'};
xtv = linspace(min(xt), max(xt), numel(xtl));
Ax.XTickLabel = xtl;
yt = Ax.YTick;
ytl = {'$\pi/2$', '$\pi/4$', '0', '$-\pi/4$', '$-\pi/2$'};
ytv = linspace(min(yt), max(yt), numel(ytl));
set(Ax, 'YTick',ytv, 'YTickLabel',ytl)
producing:
I am not certain that the y-tick labels are the way they should be. Use flip or fliplr to reverse them if necessary:
ytl = fliplr(ytl);
.

카테고리

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