How can i change the font size of XTick and YTick (x axis and y axis) in histogram of a image?

조회 수: 295 (최근 30일)
I have a image as lena.jpg, from which i was trying to obtain hist graph.
x=imread('lena.jpg');
imhist(x);
set(gca,'FontSize',15);
with this code i am able to change the font size of YTick only but i want to change font size of both. how can i do that????
  댓글 수: 2
suchismita
suchismita 2016년 6월 6일
편집: suchismita 2016년 6월 6일
R2013a.... Windows 7....
i m attaching the result which i got....
i want to increase font size for both

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

답변 (4개)

KSSV
KSSV 2016년 6월 6일
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'FontName','Times','fontsize',18)
  댓글 수: 3
Amin Mohammed
Amin Mohammed 2020년 4월 7일
It worked for me actually, even for both axes, I am using Matlab2014a.

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


KSSV
KSSV 2016년 6월 6일
편집: KSSV 2016년 6월 6일
It is changing through gui of plot. Go to edit plot and click on axes, change font. But by code need to sort.

Seemab
Seemab 2024년 6월 3일
편집: Seemab 2024년 6월 16일
I would suggest to use this.
ax = gca;
ax.FontSize = 14;
ax.LineWidth = 1;

DGM
DGM 2024년 6월 16일
편집: DGM 2024년 6월 16일
Other than manual editing, none of these answers work as simply as suggested. The reason is that imhist() creates two axes objects. The most recently-created axes (the colorbar) is not the one to which gca points. When imhist() exits, it sets gca to the axes which contains the stem plot. So if you operate on gca, that's the only axes you change.
In the simple case where there's only one thing in the figure, it's easy enough. If you have a bunch of subplots, then you'll have to figure out which pairs of axes correspond to the relevant imhist() call. Unfortunately, imhist() doesn't support any mechanism to return either handle as an output argument. It does provide a unique label for the colorbar axes, but for some bizarre reason, it doesn't label the other. There may be a more foolproof way, but I'm just going to rely on order of operations.
% some 2D image
inpict = imread('cameraman.tif');
% i'm just going to rely on the axes being the two newest children of gcf.
% that means these three lines of code must run together
imhist(inpict);
hax = findobj(gcf,'type','axes'); % all axes in the figure
hax = hax(1:2); % only care about the two most recent
% ... now all sorts of other things can change in the figure
% ... and we won't lose track of those two axes
set(hax,'FontSize',15); % set the properties of _both_ axes
  댓글 수: 2
DGM
DGM 2024년 6월 16일
I guess one other way would be to use the axes link to find which pairs of axes correspond to a single imhist() call. That might be more useful if you're trying to modify something after the entire figure has been populated.
% say i have multiple axes in a figure
% in this figure, there are 6 axes
% an image and its histogram
inpict = imread('cameraman.tif');
subplot(2,2,1)
imshow(inpict,'border','tight')
subplot(2,2,3)
imhist(inpict);
% another image and its histogram
inpict = imread('tire.tif');
subplot(2,2,2)
imshow(inpict,'border','tight')
subplot(2,2,4)
imhist(inpict);
% we didn't keep track of anything during figure creation
% so now we have to figure out which of the six axes are which.
% get all colorstripe axes, since they're the only tagged objects.
haxcs = findobj(gcf,'type','axes','tag','colorstripe');
% find the axes pairs using the links
nhgrams = numel(haxcs);
haxpairs = gobjects(2,nhgrams);
for k = 1:nhgrams
S = getappdata(haxcs(1 + nhgrams - k)); % index backwards
haxpairs(:,k) = S.linkColorStripe.Targets;
end
% say you want to set the properties of each axes pair
% the backwards indexing should mean that the first column
% of handles were the first ones created
set(haxpairs(:,1),'FontSize',12); % first pair
set(haxpairs(:,2),'FontSize',15); % second pair
The handle array haxpairs contains one column for each pair of axes. The first row is the stem axes; the second row is the colorstripe axes.
DGM
DGM 2024년 6월 16일
I might as well say it since I'm here. MIMT imhistFB() solves this problem anyway. It also solves a bunch of other problems with using imhist().
% some 2D image
inpict = imread('cameraman.tif');
% MIMT imhistFB() isn't really the same as IPT imhist() anymore.
% it will return axes handles, and it can return outputs and plot simultaneously.
[~,~,~,hax] = imhistFB(inpict,'forceplot');
% even if you didn't get the axes directly, both axes are tagged
% so it would be easy enough to find them with findobj().
% there may still be ambiguity if there are multiple histograms,
% but that's why you should just get the handles from the function call.
hax
hax =
2×1 Axes array:
Axes (imhistFB_plot)
Axes (imhistFB_stripe)

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by