plottyy and linkprop, xtick overlaping with two set of data contain large axis range difference
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I tried to use plotyy to create a 2D plot, I have 2 set of completely different data.and their x axis range is quite large as well, so consider the following code
x1=[1:10];
x2=[5:500000];
y1=2*x1;
y2=(x2).^2;
[AX,H1,H2] = plotyy(x1,y1,x2,y2);
linkprop(AX,{'Xlim','XTickLabel','Xtick'});
datetick(AX(1));
datetick(AX(2));
it only shows one graph at a time, I cant make them appear at the same time and with the same synchronize axis, which does not affect their original axis, any helps, really appreciate that.
anyone please, any hint
0 comentarios
Respuestas (1)
pfb
el 22 de Abr. de 2015
Editada: pfb
el 22 de Abr. de 2015
I tried your code out.
Both lines are plotted, but (x1,y1) is clearly flattened on the y axis (leftmost part of the window).
That makes sense, since the x ranges differ by a factor 5e4.
Plotyy basically takes care of the y axis. It makes sense when the x ranges are comparable but the y ranges are not.
In your case, they are both extremely different.
If I'm getting your problem right, you want both graphs "in the same axis"
The only way I see is to do something similar to plotyy, i.e. overlapping two different axes (use the "axes" command with the same position properties for that), and using the bottom and left axis for the first, and the top and bottom axis for the second (I'm referring to the axes properties XAxisLocation and YAxisLocation).
UPDATE This is what I mean
a1=axes;
plot(x1,y1);
a2=axes('XAxisLocation','top','YaxisLocation','right','color','none');
hold on;
plot(x2,y2,'r');
I noticed I have to hold on, otherwise the plot cancels the settings for the axes. It works also like this
a1=axes;
plot(x1,y1);
a2 = axes;
plot(x2,y2,'r');
set(a2,'XAxisLocation','top','YaxisLocation','right','color','none');
8 comentarios
pfb
el 22 de Abr. de 2015
Editada: pfb
el 22 de Abr. de 2015
Well, I guess so. For instance
datetick('x','dd-mm-yy')
works for me. The only problem is that all those numbers correspond to 1st of January 2000.
I'm not sure in what sense your x data represent dates. But probably the data in your example is not your real data.
What are your real x data? Are they obtained through the datenum function?
Ver también
Categorías
Más información sobre Two y-axis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!