how to plot two x axes and one y axis?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi guys, I know this might already been answered, but anyway: I am trying to plot graph with two x and one y axis. Basicaly I have 4 vectors: x1,y1,x2,y2. I would like to plot x1,y1 and x2,y2 and I would like to have y1 and y2 have the same y axis.
- how to specify color and markers for each pair?
- how to make ticks on both x axis the same as the values in x1 or x2 are?
- how specify legend of such plot?
- how to specify legend anx axis font style and size?
- each element of vectors y1 and y2 has its own standard deviation and I would like to show this in graph.
It's show how I would like to do in the image attached, except I would like to have 2 x-axis. thanks for help in advance!!

0 Kommentare
Antworten (1)
dpb
am 12 Okt. 2016
Bearbeitet: dpb
am 12 Okt. 2016
Follow the example in the "Using Multiple X- and Y-Axes" documentation...
hE(1) = errorbar(x1,y1,e1,'r'); % first errorbar, make it red
hAx(1) = gca; % save the axes handle
set(hAx(1),'XColor','r','YColor','r') % make the axes match for clarity
hAx(2) = axes('Position',get(hAx(1),'Position'),...
'XAxisLocation','top',...
'Color','none',...
'XColor','b','YColor','b');
hE(2) = errorbar(x2,y2,e2,'b','Parent',ax2);
The rest is simply using the linestyle and other properties; the one question about the tick marks specifically is just
set(hAx(1),'XTick',x1)
set(hAx(2),'XTick',x2)
Note that if x1 and x2 aren't the same, you'll have competing grid lines if you turn the grid lines on.
With recent versions you can use the dot syntax to address properties rather than set; I'm just old-fashioned and don't have that recent a release installed...
2 Kommentare
dpb
am 13 Okt. 2016
Bearbeitet: dpb
am 13 Okt. 2016
Good catch--I pasted the test code from command window and then decided to change variable names for the handles and missed one instance...I'll fixup the Answer to match.
For what definition of "does not work?". I created an example plot here with no problems but can't see your terminal from here. Post code and error or resulting figure with what isn't what you think should be...
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!