2

I have a .fig file with 9 subplots, arranged 3 by 3. Now I want to add labels with I have written in plotlabels(i) to subplot i, on point (xcoordinates(i),0.01). I try this

plotlabels = ['A','B','C','D','E','F','G','H','I'];
xcoordinates = [30,1000,1000,1000,1000,1000,1000,1000,1000];
fig = openfig('degreedistribution.fig');

for i = drange(1,9)
     subplot(3,3,i);
     text(xcoordinates(i),0.01,plotlabels(i),'FontWeight','bold'); hold on
end

The figure is returned with subplot 1, 4 and 7 (the left column) blanc. In the other subplots, the proper label is added in the right location. I have checked that the locations of the labels in subplot 1, 4 and 7 are compatible with the plots. So what is happening?

DM037
  • 41
  • 4

2 Answers2

1

Its the axis, I assume.

as I don't have your figure, I tried without that line:

plotlabels = ['A','B','C','D','E','F','G','H','I'];
xcoordinates = [30,1000,1000,1000,1000,1000,1000,1000,1000];
for i = drange(1,9)
   subplot(3,3,i);
   text(xcoordinates(i),0.01,plotlabels(i),'FontWeight','bold'); hold on; 
end

You can see that no labels are shown, however, all x axis are [0-1]. If I add the line axis([0 2000 0 0.02]) after text(... then I can see all labels:

enter image description here

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • I have tried it, but the problem seems to be that the command 'subplot(3,3,i)' starts a new subplot in the case i=1,4,7, and overwrites my data. Even if I change the axis, the old plot is nowhere to be found.. – DM037 Nov 13 '17 at 13:55
  • @DM037 however, we can not reproduce any of that because you are not giving a [mcve] – Ander Biguri Nov 13 '17 at 13:58
0

A minimal working example would be helpful.

You can manually assign each text to its parent axis:

for i = 1:9
     t = text(xcoordinates(i),0.01,plotlabels(i),'FontWeight','bold'); 
     t.Parent = fig.Children(i);
end
Laure
  • 373
  • 1
  • 9