Creating a graph with both descending and ascending x-axis and one y-axis
조회 수: 10 (최근 30일)
이전 댓글 표시
I am attempting to create an x-y graph in which the x-axis (log scale) has the following values:
1000, 100, 10, 1, 10, 100, 1000
The corresponding y-values are all positive.
I made such a plot by creating two subplots (A+B) and cutting and pasting them. So one graph (A) has descending x-values [1000,1] while the other (B) has ascending x-values [1,1000]. However, when I put them next to each other, I have tick marks where A and B join at x=1. I would like the ticks on the four sides of the box enclosing A+B but not at the vertical line at x=1. I don't think Matlab has an option to remove ticks on one side of a plot, i.e., the right side of A and left side of B.
Is there another way to do the above?
Thank you,
Vahid
댓글 수: 1
dpb
2019년 6월 11일
Just try setting the XTick property to [10 100 1000] on each subplot and see if joy ensues...
I'm not sure what the log axis will end up showing otomh and don't have ML open at the moment to try.
Other than that, I think you're on your own in drawing the axes manually as this is one even I've never thought of trying! :)
채택된 답변
Kelly Kearney
2019년 6월 11일
Does this do approximately what you want?
ax(1) = axes('position', [0.1 0.1 0.4 0.8], 'box', 'off', 'yaxisloc', 'left', 'xdir', 'reverse');
ax(2) = axes('position', [0.5 0.1 0.4 0.8], 'box', 'off', 'yaxisloc', 'right');
set(ax, 'xlim', [1 1000], 'xscale', 'log');
That should get all of your requirements except having tick marks across the top of the plot. If you need those, you can add a couple additional axes, for decoration only:
ax(3) = copyobj(ax(1), gcf);
ax(4) = copyobj(ax(2), gcf);
set(ax(3:4), 'ycolor', 'none', 'xaxisloc', 'top', 'xticklabel', '', 'color', 'none');
댓글 수: 1
Kelly Kearney
2019년 6월 12일
And to add data to the axes, make sure you set their hold state to on (or use a low-level plotting routine that doesn't reset axes properties); otherwise, many of those custom settings will be reset:
hold(ax(1), 'on');
hold(ax(2), 'on');
x = logspace(0,3,10);
y = rand(10,1);
plot(ax(1), x, y);
plot(ax(2), x, y);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!