Creating a graph with both descending and ascending x-axis and one y-axis
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vahid Askarpour
le 11 Juin 2019
Commenté : Kelly Kearney
le 12 Juin 2019
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 commentaire
dpb
le 11 Juin 2019
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! :)
Réponse acceptée
Kelly Kearney
le 11 Juin 2019
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 commentaire
Kelly Kearney
le 12 Juin 2019
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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!