Format tick labels in histogram subplots

15 次查看(过去 30 天)
I want to plot 2 subplots both being histograms. For the first set, I want there to be 0.2 increments starting at 22, then, 22.2, 22.4, etc. until 34.
Same for the second set, except different limits based on the data I had on file.
Problem: When I graph this, the tick marks for suplot 1 is: [22.00 24.00, ... 34.00] But when squinting I can see the graph really is spaced out 0.2.
Same for second subplot except spaced out 0.25. How do I correct my code below?
I found I should use gca, but it doesn't seem to be working. Where should I add:
ax = gca;
ax.XAxis
xtickformat('%, 0.2f')
load data1.txt; %load text file while has 200 rows of data with 2 columns
x = data1(:,2); % take all rows in col 1
y = data1(:,1); %take all rows in col 2
figure
subplot (2,1,1)
histogram (x)
histogram(x, [22: 0.2: 34]) %the 22 to 34 is just the x limits I set for the data
subplot (2,1,2)
histogram (y)
histogram(y, [-1.5: 0.25: 1.5]) %change limits for your set of data.
Thanks guys!

采纳的回答

Jyotsna Talluri
Jyotsna Talluri 2020-4-2
Set the XTick Property of the Axes after plotting the histogram as the plot itself adjusts the XTicks based on the values of data being plotted .
subplot (2,1,1)
ax = gca;
ax.XLim = [22 34];
histogram (ax,x);
ax.XTick = 22:0.2:34;
subplot (2,1,2)
ax2 = gca;
ax2.XLim =[-1.5 1.5];
histogram (ax2,y)
ax2.XTick = -1.5:0.25:1.5;.
Refer to the below link for more information

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by