Plotting with 2 different axes but same scale

12 vues (au cours des 30 derniers jours)
dlyman
dlyman le 13 Juil 2015
Commenté : dpb le 17 Juil 2015
I'm trying to graph charge and discharge data of a single cycle. I've attached what currently is graphed. I'm graphing 4 different variables: Discharge capacity vs, discharge voltage and charge capacity vs charge voltage. Currently have tried variations of plotyy and plotxx.
Here are the issues I'm trying to fix.
  1. The scale for voltage is the same (min 3 max 4.4) but the charge voltage and discharge voltage do not all have the same values. I just want to normalize the 2 y-axes.
  2. I'm setting up the graph so discharge is shown from left to right and charging will be shown from right to left. I will need 2 separate x-axes to graph the corresponding data, but again need it normalized so the axes are on the same scale.
I just wanted to know if there's an easy way to do this or if manually building the plot, axes, and plotting lines is the best way to go about this.

Réponses (1)

dpb
dpb le 13 Juil 2015
Modifié(e) : dpb le 14 Juil 2015
OK, what I'd probably do is start with plotyy and save the handles to the two axes so you can more easily modify them a little--to solve 1)
hA=plotyy(x1,y1,x2,y2); % dummy plotyy just saving handles; use your variables
linkaxes(hA,'y') % link the two y axes to stay together
ylim(hA(1),[3 4.4]) % set the range desired
set(hA,'yticklabel',num2str([get(hA(1),'ytick')].','%0.1f')) % format to one decimal
Now for problem #2,
set(hA(2),'xdir','reverse','xaxislocation','top')
ADDENDUM I didn't really follow what you mean by the normalization reference; the key to the above is that the two axes are the same size/position where you're making a lot of difficulty by trying to have the second axes at a different location than the first thus making the length of the two y-axes different which fouls up the limits/scaling.
  1 commentaire
dpb
dpb le 17 Juil 2015
ADDENDUM 2 Altho appear to have disappeared, on the off chance't check again, I'd add that if you do require the second, reversed axes also at the bottom, when you create it simply make the y height of that axes object very small and use it only for displaying the reversed x coordinates; plot into the other as above for the y axes. I've thought (and believe I've made an enhancement request in the past) that it would be a useful feature if there were a property of axes that would just draw an x- or y- axis for such purposes.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by