向Matlab图例添加额外的空格(用于psfrag) [英] Add extra whitespace to matlab legend (for use with psfrag)

查看:1198
本文介绍了向Matlab图例添加额外的空格(用于psfrag)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在文本右侧的Matlab图例上填充空白?我将psfrag(和Adobe illustrator用于其他一些图表修改)组合使用,并将用等式替换图中的占位符文本.问题是它在占位符文本上紧紧地包围了框,而我想为方程式留出空间

How to pad white-space on a matlab legend to the right of the text? I am using a combination of psfrag (and adobe illustrator for a few other diagram modifications), and will replace the placeholder text in a figure with an equation. The problem is that it tightly bounds the box on the placeholder text, while I want to leave room for my equation

从简单的图形开始;

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

我真正想要的间距是这样的

The spacing I really want would be something like this with

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

哪里!!!!!!!!实际上是空格,并且实际上存储为一个字符"A".

where the !!!!!!!! is actually whitespace, and it really is stored as one character 'A'.

一些似乎不起作用的东西:

A few things which did not seem to work:

  1. 一个明显的解决方案是:只需添加诸如"A !!!!!!!!!!!!"之类的文本.并用psfrag中的方程式替换整个文本.但是,如果我使用Adobe Illustrator触摸文件,则它将文本转换为单个字符,这会破坏psfrag(请参见

  1. One obvious solution is: just add in text such as "A!!!!!!!!!!!!" and replace the whole text with my equation in psfrag. However, if I touch the file with Adobe Illustrator, then it converts the text to individual characters, which breaks psfrag (see http://engineeringrevision.com/314/getting-illustrator-to-play-nicely-with-psfrag/ for example). So I really need to just have the 'A' character as the string.

另一种方法是尝试拉伸框,但是改变位置或纵横比会相应地拉紧文本和线条.

Another is to try to stretch the box, but chanking the position or the aspect ratio streches the text and line accordingly.

例如,以下内容只是拉伸宽度

For example, the following just 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);

  1. legendflex文件看起来非常有趣,但是我认为对空白缓冲的控制仅适用于图例本身的位置.
  1. The legendflex file looks very interesting, but I think the control over the whitespace buffering was only for the position of the legend itself.

推荐答案

您可以添加前32个ASCII代码(不可打印的字符)中的任何一个来创建空格.不确定它是否可以与psfrag一起使用.

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

此处,这段代码使用ASCII代码3创建了30个空格.

Here, the piece of code creates 30 spaces using ASCII code 3.

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

编辑

另一种可能性.您可以使用图例中的手柄.在这里,将图例的文本从10个字符更改为1个字符不会更改图例框的大小.

Another possibility. You can use the handles from legend. Here, changing the legend's text from 10 to 1 characters do not modify the size of the legend box.

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

-查看注释:另存为.eps会在创建的图像文件中恢复旧字符串.

-- see comments: saving as .eps brings back the old string in the image file created.

这篇关于向Matlab图例添加额外的空格(用于psfrag)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆