I use the code below to right align the "X tick labels" of my boxplot and adjust the distance to the x axis. This works fine when the figure is created. However, after reopening (or exporting to another format) the distance to the x axis is changed to default (far away from the axis) while the right alignment is kept.
Does anyone know how to fix this issue?
boxplot(all_values, all_names, 'labelorientation', 'inline');
text_h = findobj(gca, 'Type', 'text');
for cnt = 1:length(text_h)
set(text_h(cnt),'HorizontalAlignment', 'right');
yshift=get(text_h(cnt), 'Position');
yshift(2)=-5;
set(text_h(cnt), 'Position', yshift);
end
saveas(gcf,'path/boxplot.fig');

3 Kommentare

Oleg Komarov
Oleg Komarov am 8 Jun. 2012
The default distance is NOT far away from the (x) axis. Are you sure you don't want to put a +5 instead of -5?
Using this example code I cannot reproduce your problem:
boxplot(rand(100,2), {'a','second'}, 'labelorientation', 'inline');
text_h = findobj(gca, 'Type', 'text');
set(text_h,{'HorizontalAlignment'}, {'right'});
yshift = get(text_h, 'Position');
yshift = cellfun(@(y) [y(1) y(2)+5 y(3)],yshift,'un',0);
set(text_h, {'Position'}, yshift);
saveas(gcf,'boxplot.fig');
Win 7 64, R2012a 64
Hannes
Hannes am 8 Jun. 2012
The default position from the axis is -40. If I run your code with y(2)+35 I get the labels where I would like to have them. If I close the figure on the screen and open the one that has been saved the distance is back at -40 (same problem as with my code). It does not seem to save the new label positions and it also doesn't export them.
I'm using R2010b on a Mac. Maybe the problem has to do with this...
Oleg Komarov
Oleg Komarov am 8 Jun. 2012
Actually I could not notice with a +5 but I do have the same problem and see my answer too.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 8 Jun. 2012

2 Stimmen

Problem NOT solved, but documented. It's a BUG: http://www.mathworks.co.uk/support/bugreports/details.html?rp=228710

2 Kommentare

Hannes
Hannes am 8 Jun. 2012
Thanks to both of you for taking your time!
Have a good weekend
Hannes
Oleg Komarov
Oleg Komarov am 8 Jun. 2012
I have not tried but you could try to paste text objects in the position of the labels and check if this keeps on happening.
Good weekend

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

the cyclist
the cyclist am 8 Jun. 2012

0 Stimmen

I have two suggestions.
The first is to just try using print() function rather than saveas(), and to play around with different output formats within the command. I suspect that that is not going to solve your issue, as the primitive elements inside the guts of MATLAB are probably going to be the same. (Just guessing here.)
The second suggestion is to try the very nice FEX entry "export_fig":
It is generally much better at "what you see is what you get" between the screen image and the resulting file.

3 Kommentare

Hannes
Hannes am 8 Jun. 2012
I didn't mention that I tried all this including "export_fig". As you nicely word it, the problem may be hidden deeper within MATLAB ;)
Thank you anyway
Hannes
the cyclist
the cyclist am 8 Jun. 2012
Hm. Are you able to include a highly distilled example of your code that illustrates the problem?
Hannes
Hannes am 8 Jun. 2012
Oleg's example reproduces the problem very nicely but only on my system as it seems.

Melden Sie sich an, um zu kommentieren.

Kirsten
Kirsten am 18 Jul. 2014

0 Stimmen

anyone know how to fix this in the boxplot m-file? I make boxplots all the time and dealing with moving the labels so they aren't RIGHT ON TOP of the axis is making me crazy!

Kategorien

Mehr zu Live Scripts and Functions finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Jun. 2012

Beantwortet:

am 18 Jul. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by