필터 지우기
필터 지우기

Two area plots with separate y axes and single log x-axes

조회 수: 2 (최근 30일)
Stephen Faul
Stephen Faul 2011년 7월 1일
Hi folks.
Yesterday I had the need to overlay two histograms, with logarithmically scaled bin widths on a plot with a separate y-axis for each. The histogram needs to be filled in colour (as opposed to a simple line plot) and if possible semi-transparent. The combination of these requirements is causing problems.
Calculating the actual histogram data is no problem:
x1 = logspace(pow10LowerThanMin1,pow10HigherThanMax1,400);
n1 = hist(data1,x1);
x2 = logspace(pow10LowerThanMin2,pow10HigherThanMax2,400);
n2 = hist(data2,x2);
And plotting just the line plots for that is no problem:
[axes_handles,plot_handle1,plot_handle2]=plotyy(x1,n1,x2,n2);
set(axes_handles(1),'XScale','Log');
set(axes_handles(2),'XScale','Log');
So now I want to put in the fill areas. No problem, just use the axes handles as used above for the area function:
hold on;
area1_handle = area(axes_handles(1),x1,n1);
area2_handle = area(axes_handles(2),x2,n2);
The first area command works fine, plot comes out perfectly. The second area command returns with an error:
??? Invalid object handle
Error in ==> specgraph.areaseries.areaseries
at 19
h = specgraph.areaseries('parent',parent);
Error in ==> area at 85
h = [h
specgraph.areaseries('YData',datachk(y(:,k)),
...
It doesn't seem to be a problem with the axes handles themselves either, because if I try the second handle first it works, and the error occurs when calling area with axes_handles(2).
I've checked the axes_handles values against the axes handles returned by
get(gcf,'Children')
at each step and they are equal all the way through. After the error, only the first axis handle exists is returned by the above command.
So it appears that this is a bug of some sort. I've tried replacing the "area" function with a "fill" function and using "hist" with the "'histc'" option, but they all fail in similar fashion.
So my question is, does somebody have another way to generate my required plot?
Regards, Stephen

채택된 답변

Jan
Jan 2011년 7월 1일
Set the NextPlot property of the AXES manually instead on hold('on'), because the later concerns the first axes only:
axesH = plotyy(1:5, rand(5), 6:7, rand(5));
set(axesH, 'XScale', 'log', 'NextPlot', 'add');
area(ax(1), 1:2, 0:1);
area(ax(2), 3:4, 0:1);
HOLD acts on the first axes only (even HOLD('all')):
axesH = plotyy(1:5, rand(5), 6:7, rand(5));
get(axesH, 'NextPlot') % >> 'replace', 'replace'
hold('on');
get(axesH, 'NextPlot') % >> 'add', 'replace'
  댓글 수: 2
Stephen Faul
Stephen Faul 2011년 8월 10일
Thanks, sorted.
zohar
zohar 2011년 8월 10일
as a matter of fact
axesH = plotyy(1:5, rand(5), 6:10, rand(5));
set(axesH, 'XScale', 'log', 'NextPlot', 'add');
area(axesH(1), 1:2, 0:1);
area(axesH(2), 3:4, 0:1);
axesH = plotyy(1:5, rand(5), 6:10, rand(5));
get(axesH, 'NextPlot') % >> 'replace', 'replace'
hold('on');
get(axesH, 'NextPlot') % >> 'add', 'replace'

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by