XLim for bar plot with several data series

조회 수: 8 (최근 30일)
ID#
ID# 2018년 10월 20일
답변: ID# 2018년 10월 21일
I created a bar plot with three data series and bins 0 to 20. The automated process creates a plot with bins -5 to 25. I'm wondering why and I'm wondering how I could set the XLim property? b = bar(...) and b.XLim doesn't work. b(1).XLim doesn't work either.
bins = 0:20
figure;
b2 = bar(bins,[s1 s2 s3],'hist','FaceColor','flat');
s1, s2, and s3 are vectors (data series).
XLim = [0, 20];
gives me the following error message:
Expected one output from a curly brace or dot indexing expression, but there were 3 results.
Otherwise:
b2(1).XLim = [0, 20]
Unrecognized property 'XLim' for class 'matlab.graphics.primitive.Patch'.
As well as:
b2(1).XLim = {[0, 20] , [0, 20] , [0, 20]}
Unrecognized property 'XLim' for class 'matlab.graphics.primitive.Patch'.
b2.XLim = {[0, 20] [0, 20] [0, 20]}
Expected one output from a curly brace or dot indexing expression, but there were 3 results.
b2.XLim = {[0, 20] ,[0, 20], [0, 20]}
Expected one output from a curly brace or dot indexing expression, but there were 3 results.
Does anyone know how I can set the XLim value? It works with the Plot Tools.
Thank you very much in advance!

채택된 답변

ID#
ID# 2018년 10월 21일
ax = gca;
ax.XLim = [0, 20];
Did the trick! Thank you Star Rider, you brought me onto the right path!

추가 답변 (1개)

Star Strider
Star Strider 2018년 10월 20일
Since 'XLim' is an axes property, do this:
figure
bar(rand(1,200), 'hist','FaceColor','flat')
XL = get(gca, 'XLim')

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by