Add extra spaces to matlab legend (for use with psfrag)

How to place white space on matlab legend to the right of the text? I will use a combination of psfrag (and adobe illustrator for several other diagram modifications) and replace the placeholder text in the figure with an equation. The problem is that it tightly limits the placeholder text field, while I want to leave room for my equation

Start with a simple number;

h_plot = plot([0 1], [0 1]); h_legend = legend('A',0); 

The interval that I really want will be something like

 h_plot = plot([0 1], [0 1]); h_legend = legend('A!!!!!!!!',0); 

Where!!!!!!!! is actually a space, and it really is stored as a single “A” character.

A few things that don't seem to work:

  • One obvious solution: just add to the text, for example, "A !!!!!!!!!!!!!" and replace all text with my equation in psfrag. However, if I touch a file using Adobe Illustrator, it converts the text to separate characters, which causes psfrag to break (for example, http://engineeringrevision.com/314/getting-illustrator-to-play-nicely-with-psfrag/ ), So I really just need to specify the character "A" as a string.

  • Another is trying to stretch a box, but beating a position or proportion stretches the text and line, respectively.

For example, the following simply stretches the width

 h_plot = plot([0 1], [0 1]); h_legend = legend('A',0); leg_pos = get(h_legend,'position'); leg_pos(3) = leg_pos(3) * 2; set(h_legend, 'position', leg_pos); 
  • The legendflex file looks very interesting, but I think that the control over buffering in the form of spaces was only for the position of the legend itself.
+4
source share
3 answers

You can add any of the first 32 ascii codes (non-printable characters) to create a space. Not sure if it will work with psfrag though.

Here the code snippet creates 30 spaces using ASCII code 3.

 h_plot = plot([0 1], [0 1]); h_legend = legend([ 'A' repmat(char(3),1,30) ],0); 

EDIT

Another opportunity. You can use descriptors from the legend. Here, changing the legend text from 10 to 1 character does not change the size of the legend window.

 [~,OBJH,~,~] = legend('0123456789'); % display a legend of 10 characters set(OBJH(1), 'String', 'A'); % change its String to 1 character 

- see comments: saving as .eps returns the old line in the created image file.

enter image description here

+2
source

To add extra space to the legend just use

 { } -> { "add how much space you wish between two brackets" } 

eg:

 legend( 'A{ }','b{ }' ) 
+1
source

The legend function has an argument of "Location". You can pass it a vector, i.e.

 plot(1:10) legend('Sometext', 'Location', [0.20, 0.1, 0.75, 0.25]) 

where the last vector can be interpreted as [Position_Right_in_pct, Position_Top_in_pct, Horizontal_Stretch, Vertical_Stretch]

0
source

Source: https://habr.com/ru/post/950166/


All Articles