how to modify the axis labels in the attached plot?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
Walter Roberson
el 16 de Sept. de 2020
Editada: Walter Roberson
el 16 de Sept. de 2020
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 comentarios
Walter Roberson
el 16 de Sept. de 2020
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
el 16 de Sept. de 2020
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/361801/image.png)
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);
.
0 comentarios
Ver también
Categorías
Más información sobre Labels and Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!