本文介绍了matplotlib:Humor Sans 不能正确显示重音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我选择 Humor Sans,这就是我从 matplotlib 得到的:

This is what I get from matplotlib if I choose Humor Sans:

所以DISTÀNCIA"显示为DIST?NCIA".它与其他字体很好地显示.

So "DISTÀNCIA" showed as "DIST?NCIA". It is well-displayed with other font.

代码在这里:

# -*- coding: utf-8 -*-
from matplotlib import pyplot as plt
import numpy as np
from pylab import *

# Estil de còmic XKCD
plt.xkcd()

# Etiquetes
fig = plt.figure()
plt.title("Distància vs velocitat de les carreres d'atletisme")
plt.xlabel('distància')
plt.ylabel('velocitat de l\'atleta (homes)')

# Configuracions
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim([-10, 12000])
ax.set_ylim([-1, 11])
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()


# Noms
plt.annotate('5000m', xy=(5000, 5.6), arrowprops=dict(arrowstyle='->'), xytext=(4500, 4))

# Data
data = np.genfromtxt('taula-fins-10000.csv', delimiter=';', skip_header=1)
event7 = [ [z[0], z[1]] for z in data if z[0] == 5000]
x = [e[0] for e in event7]
y = [e[1] for e in event7]

# Dibuix
plt.plot(x, y, 'o')
plt.savefig("grafic-amb-nomes-una-prova.png")

是不是字体有问题?

推荐答案

我知道这是一个老问题,但也许它仍然有用.

I know this is an old question, but maybe it can still be useful.

不幸的是,您面临的问题取决于 Humor Sans 本身,并没有简单的解决方案.该字体是根据美国文字制作的,模仿 xkcd 漫画中使用的字体.因此,它根本没有带重音的字母.

Unfortunately, the problem you are facing depends on Humor Sans itself, and has no easy solution. The font was made having US words in mind, mimicking the one used on xkcd comic strips. For this reason, it comes with no accented letters at all.

我不知道这在西班牙语中是否是惯例,但一些印欧语言使用 - 有点丑陋 - 的解决方法,即在无重音字母后放置一个撇号:à ---> a';é ---> e'等等……

I don't know if it's customary in spanish, but some indoeuropean languages use the -somewhat ugly- workaround of putting an apostrophe after the unaccented letter:à ---> a'; é ---> e'and so on...

这篇关于matplotlib:Humor Sans 不能正确显示重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:07
查看更多