在Matlab中更改图形字体不起作用 [英] Changing figure fonts in Matlab has no effect

查看:586
本文介绍了在Matlab中更改图形字体不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签和传说中呈现希腊字符时遇到问题,所以我认为切换字体可能会有所帮助。因此,我发现了一个更大的问题 - Matlab似乎并不尊重我的字体设置。



我试过了,当然,


$ b $

  set(gcf,'FontName','Ubuntu')
set(gca,'FontName','Ubuntu')

还有一些像

  set(findall(gca,'type','text'),'FontName','Ubuntu')



$ p
$ b $ pre $ set(0,'DefaultAxesFontName','Ubuntu')

我也尝试切换渲染器,使用

  set(0,'DefaultFigureRenderer','OpenGL')%也试过'zbuffer'和'画家'



我甚至进入了图上的属性编辑器,并手动改变了字体。不管我做什么,字体都会出现相同的,难看的等宽字体(参见下图)。该图片通过图中菜单栏中的另存为...命令进行保存, print -dpng'fonttest.png'也不能用。



fc-list 在我的终端中, listfonts 在Matlab命令提示符下, Ubuntu 字体已安装且可用。我正在运行Matlab R2012b。
$ b

如何在我的数据中设置字体?

更新:

正如评论中所建议,我试图看看这是否可能是一个>问题。果然,从OpenJDK切换到Oracle Java帮助,但还不够 - 我可以使用Helvetica和其他一些,但我不能自由选择我安装的字体。例如,Ubuntu字体不起作用。 (但是,在Matlab的主GUI中,我已经在菜单等中将字体更改为Ubuntu,并且在编辑器和命令窗口中将Consolas更改为OK。)



无论何时我选择一个不能正常工作的数字字体,Matlab都会使用下面的屏幕截图中显示的内容作为后备。

$ b $ p q f 这里真的应该是希腊字母pi,theta和phi(它们是用 \pi 等指定的),但是我猜字体doesn没有那些角色。在第三个阴谋的y标签中的奇怪的东西是瑞典ö - 它不应该是一个编码的问题,因为该文件被保存为UTF-8,这也是什么 slCharacterEncoding 返回,所以我认为这也是一个字体问题。

解决方案

<安装xfonts-75dpi和xfonts-100dpi对我来说是默认设置。

  sudo apt-get install xfonts -75dpi xfonts-100dpi 

然后注销并重新登录。

这似乎允许两个符号(例如\pi)和字体大小(例如set(h,'FontSize',14))改变(使用默认的Matlab字体)。 b
$ b

机器设置:Ubuntu 12.04 x64 with Matlab R2012b

I'm having problems with rendering Greek characters in my labels and legends, so I thought maybe switching fonts would help. Thus, I discovered an even bigger problem - Matlab doesn't seem to honor my font settings at all.

I've tried, of course,

set(gcf, 'FontName', 'Ubuntu')
set(gca, 'FontName', 'Ubuntu')

but also things like

set(findall(gca, 'type', 'text'), 'FontName', 'Ubuntu')

and

set(0,'DefaultAxesFontName', 'Ubuntu')

I also tried switching renderers, with

set(0, 'DefaultFigureRenderer', 'OpenGL') % also tried 'zbuffer' and 'painters' 

I even went into property editor on the figure, and manually changed the fonts. Regardless of what I do, the font comes out with the same, ugly monospaced font (see figure below). This picture is saved with the Save As... command in the menu bar of the figure, but e.g. print -dpng 'fonttest.png' doesn't work either.

I've double-checked both with fc-list in my terminal, and listfonts at the Matlab command prompt, that the Ubuntu font is installed and available. I'm running Matlab R2012b.

How do I set the fonts in my figures?

UPDATE:
As suggested in comments, I tried to see if this is might be an
issue with Java on Ubuntu. Sure enough, switching from OpenJDK to Oracle Java helped, but not enough - I can use Helvetica and a few others, but I can't choose freely among my installed fonts. The Ubuntu font, for example, does not work. (It does, however, in the main GUI of Matlab - there I've changed the fonts to Ubuntu in menus etc, and Consolas in the editor and command window, and it renders OK.)

Whenever I choose a figure font that doesn't work, Matlab uses what's shown in the screenshot below as fallback.

The p, q and f here should really be the greek letters pi, theta and phi (they're specified with \pi etc) but I guess the font doesn't have those characters. The weird stuff in the y-label of the third plot is a Swedish ö - it shouldn't be a problem with encodings, because the file is saved as UTF-8, which is also what slCharacterEncoding returns, so I assume that's also a font issue.

解决方案

Installing xfonts-75dpi and xfonts-100dpi did the trick for me for the default settings.

sudo apt-get install xfonts-75dpi xfonts-100dpi

and then log out and log in again.

This seems to allow both symbols (e.g. \pi) and font size (e.g. set(h, 'FontSize', 14)) changes (using the default Matlab font).

Machine setup: Ubuntu 12.04 x64 with Matlab R2012b

这篇关于在Matlab中更改图形字体不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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