How to plot this graph?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NGUYEN Quang Hung
el 28 de Mzo. de 2014
Comentada: dpb
el 1 de Abr. de 2014
Hi everyone, Can anybody show me how to plot this graph on Matlab? It looks like many subplot in a same row, separately, but I can't find any document in the internet
Thanks
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159634/image.jpeg)
0 comentarios
Respuesta aceptada
Joseph Cheng
el 28 de Mzo. de 2014
You'll have to add to this more to get it to look pretty or to fit your data. However code below shows examples of what you're trying to accomplish. I don't know about labeling % of BFS to be in the middle. I know the File Exchange has some good Axes labeling, or you can insert the text knowing the total length of all the subplots.
x=[0 30 50 80]; %set x axis ticks
y=rand(4); %get something to plot
h1=subplot(1,2,1); %setup subplot1
plot(x,y,'-.'); %plot subplot1
box off % leave only x and y axes
xlim([-10 90]) %setup some buffer between the subplots
set(h1,'Xtick',x) %set the x axis ticks to show only x
h1_pos = get(h1,'Position'); %get the position data for sublot1.
y2 = 10*y.^2; %make something up for subplot2
h2=subplot(1,2,2); %make subplot2
plot(x,10*y,'-.'); %plot subplot2
y2lim = get(h2,'YLim'); %get the y limits of subplot 2.
set(h1,'Ylim',[0 y2lim(2)]) %set subplot1 to be on the same scale (just did 0 but maybe min of ylim for subplot1
box off
set(h2,'Ycolor',[1 1 1]) %make the Y axis line white
xlim([-10 90])
set(h2,'Xtick',x)
h2_pos=get(h2,'Position');
set(h2,'Position',[h1_pos(1)+h1_pos(3) h2_pos(2:end)]) %using position of subplot1 put subplot2next to it.
set(h2,'YTickLabel','') %remove y tick lables.
4 comentarios
Joseph Cheng
el 1 de Abr. de 2014
actually depending on where/how you are labeling, you can try using the underscore _ like 'Na_2O'. I just feel Matlab is a bit inconsistent on which type of text labeling it can work in. However the inconsistent activity is probably due to my infrequent need to use subscripts and it actually works in 95% of the cases except when i try to.
dpb
el 1 de Abr. de 2014
Well, it depends on having the TeX interpreter on as noted. Most places honor it excepting tick labels one notable exception I can think of otomh
Más respuestas (1)
dpb
el 28 de Mzo. de 2014
Editada: dpb
el 28 de Mzo. de 2014
Either create multiple x-axes at the right positions without the associated y-axes displayed or, perhaps easier, add an offset of the cumulative maximum of axis to left plus an offset to the x-values of each of the 2nd and higher groups of data.
That is, for the second group plot x+80 in lieu of x, (which looks like would be about 110 in plot units) then set 'xtick' and '_xticklabel_' to the desired positions and labels. The overall xlim will be from roughly [-10 450] it looks like guesstimating quickly.
ADDENDUM:
Here's at least one start towards using multiple axes --
H=axes('position',[.13 .11 .7744 .815],'xtick',[],'ytick',[]);
for i=1:4,h(i)=subplot(1,4,i);end
set(h(2:4),'ycolor',[1 1 1],'ytick',[])
set(h(1),'xlim',[-10 80],'xtick',[0 30 50 80])
set(h(2),'xlim',[30 80],'xtick',[30 50 80])
You should get the drift...need to set background for H to fill in the gaps between the various subplots, finish setting their limits and then you can plot your data into them...
ADDENDUM 2:
While I don't have time at the moment to actually 'spearmint, came to me that the way to deal w/ the space between the axes isn't by the underlying axes but by setting up the position and width of the four subplots such that they precisely fill the area. To do this in words would be--
- Set the four via subplot() to default positions,
- Retrieve left position of first and right of last (which is the left+width entries from the position vector for it)
- find new width as (End-Start)/4 from above and
- Set new position to [start,bottom,newwidth,height] where each start_i is start_i-1+width
Then you make the spacing between x axis marks as above with an offset from the initial tick position. Shouldn't be too bad...
4 comentarios
Joseph Cheng
el 31 de Mzo. de 2014
To get rid of the ticks i use the trick of setting the y ticks to
set(h2,'Ytick',[])
but it looks like i forgot to include that and setting the line color to white.
dpb
el 31 de Mzo. de 2014
Editada: dpb
el 31 de Mzo. de 2014
That looks ok if you just do subplot and/or axes but as soon as you plot something onto that axis then it insists on showing the tick marks on the RH axis as well. So what shows up where the LH subplot-2 axes are are also the RH tick marks from subplot-1 that are on because of needing to use the LH axis ticks for it.
Just thought of another workaround, though...
>> for i=1:5,h(i)=subplot(1,5,i);p(i,:)=get(h(i),'position');end
>> p(1,3)=0;set(h(1),'position',p(1,:))
Error using set
Width and height must be > 0
>>
Well, that didn't work, but
>> p(1,3)=0.001;set(h(1),'position',p(1,:))
does to just show the left axis. Now redistribute 2:5 across the range and use first for y-axis only. Then can turn the ytick off on all and not have the annoying RH axis tick that there's no way to turn off afaik once you plot onto the axis if you use ticks at all.
Ver también
Categorías
Más información sobre Visual Exploration 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!