MATLAB Answers

Creating a graph with both descending and ascending x-axis and one y-axis

20 ビュー (過去 30 日間)
Vahid Askarpour
Vahid Askarpour 2019 年 6 月 11 日
コメント済み: Kelly Kearney 2019 年 6 月 12 日
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
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! :)

Sign in to comment.

採用された回答

Kelly Kearney
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
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);

Sign in to comment.

その他の回答 (0 件)


Translated by