2

I have legend text that in matlab behaves as

set(gcf,'DefaulttextHorizontalAlignment','left'); 

now I am attempting to replicate this in octave, but for some reason octave seems to ignore the above command.

I am using cygwin Xwin octave and GNUPlot.
(I am not trying to move the text to the other-side of the "line" legend('left'))

Doing some tests, it turns out that I can set the property, but it isn't affecting anything.

LegendHandle = legend( phvec, legendvec, 'Location', 'NorthEastOutside' );
legtxt=findobj(LegendHandle,'type','text');
get(legtxt(1),'HorizontalAlignment') %% returns left
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • I don't get it. If you set the default to `left` and then `get()` returns left, doesn't that mean it is not working? Can you give an exact example, code snippet with actual values, that reproduces the problem and what you were expecting? – carandraug Jul 29 '14 at 15:30
  • [image of the problem](https://scontent-a-vie.xx.fbcdn.net/hphotos-xfa1/t1.0-9/10577029_695120180543442_8393805635688081737_n.jpg). – Simon Holtz Jul 30 '14 at 08:08
  • I can't replicate. It works for me. Are you using an outdated version of Octave? – carandraug Jul 31 '14 at 12:06
  • I take back what you said. I can replicate your problem if using gnuplot. I recommend you switch the graphics toolkit to fltk which should already be the default in recent Octave versions. – carandraug Jul 31 '14 at 12:16

2 Answers2

2

It seems Gnuplot supports the option to change the legend horizontal alignment, but Octave doesn't provide the access to this function in Gnuplot (although it works with FLTK). You simply can't do anything about it, except filing a feature request on the Octave tracker.

Source: http://octave.1599824.n4.nabble.com/set-horizontalalignment-for-legend-text-td2218246.html

So yes, there's currently no solution to left align the legend text using gnuplot, the only thing you can do to remove this awful blank space is, as you said, to use legend('left') to swap the text to the left of the symbols.

gaborous
  • 15,832
  • 10
  • 83
  • 102
0

I can replicate your problem but only if using gnuplot. It works with other graphics toolkits.

While gnuplot was Octave's default graphics toolkit for a long time, the Octave developers have been slowly replacing it with their own alternative in order to avoid its limitations. I believe recent versions of Octave will already default to fltk but you can change it yourself:

octave-cli-3.8.1> graphics_toolkit fltk
octave-cli-3.8.1> graphics_toolkit  # confirm
ans = fltk
octave-cli-3.8.1> x = 0:0.1:10;
octave-cli-3.8.1> figure;
octave-cli-3.8.1> plot (x, [sin(x); cos(x)]);
octave-cli-3.8.1> legend ("long sin", "cos", "Location", "NorthEastOutside");

plot with legend text on the left using fltk

carandraug
  • 12,938
  • 1
  • 26
  • 38
  • thanks, though I cant use fltk as I get segmentation faults (might be the same problem as http://stackoverflow.com/questions/21955036/problems-plotting-with-octave ) – Simon Holtz Aug 04 '14 at 08:48
  • @SimonHoltz if you're getting a segfault you should report it. The question you just linked to, was caused by a bad graphics card driver and was solved by reinstalling them. Also, since you're using Windows, did you try the the [MXE builds](http://wiki.octave.org/Octave_for_Microsoft_Windows#Octave_3.8_MXE_Builds)? There is no official builds of Octave for Windows, but if any ever comes to be, it will be based on these. – carandraug Aug 04 '14 at 09:07
  • @carandraug: yes FLTK has issues with bad OpenGL drivers, but modern integrated Intel HD Graphics and some AMD Radeon also are plagued by the problem (not only old drivers, so there's nothing that can be done by users in this case). This is currently being investigated by the Octave dev team: https://savannah.gnu.org/bugs/?42534 – gaborous Nov 06 '14 at 23:47