Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 643c994

Browse filesBrowse files
committed
Add faq for using matplotlib
1 parent d82fcfc commit 643c994
Copy full SHA for 643c994

File tree

Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-0
lines changed
Open diff view settings
Collapse file

‎docs/faq.rst‎

Copy file name to clipboardExpand all lines: docs/faq.rst
+30Lines changed: 30 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,33 @@ virtualenv.bundle.zip添加到module的搜索路径中,示例代码如下: :
185185
2. 有些包是not-zip-safe的,可能不工作,有待验证。 含有c扩展的package
186186
不能工作。
187187

188+
Matplotlib使用常见问题
189+
-----------------------
190+
191+
SAE环境不支持matplotlib的interative模式,所以无法使用 `pyplot.show()` 直接来显示图像,只能使用
192+
`pyplot.savefig()` 将图像保存到一个输出流中(比如一个cStringIO.StringIO的实例中)。
193+
194+
如果想要在matplotlib中显示中文,可以使用以下任一方法。
195+
196+
方法一: ::
197+
198+
import os.path
199+
from matplotlib.font_manager import FontProperties
200+
zh_font = FontProperties(fname=os.path.abspath('wqy-microhei.ttf'))
201+
import matplotlib.pyplot as plt
202+
plt.title(u'中文', fontproperties=zh_font)
203+
204+
方法二: ::
205+
206+
import os
207+
# 设置自定义字体文件所在目录路径,多条路径之间使用分号(:)隔开
208+
os.environ['TTFPATH'] = os.getcwd()
209+
import matplotlib
210+
# 设置默认字体名
211+
matplotlib.rcParams['font.family'] = 'WenQuanYi Micro Hei'
212+
import matplotlib.pyplot as plt
213+
plt.title(u'中文')
214+
215+
其中方法一适用于ttf和ttc字体,方法二适用于只适用于ttf字体
216+
217+
如果有 `matplotlibrc` 配置文件,请将该文件与index.wsgi放在同一个目录下(默认的当前路径)。

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.