Format tick labels in histogram subplots
조회 수: 33 (최근 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!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!