Created
April 16, 2010 08:38
-
-
Save mrluanma/368172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: test_matplotlib_chinese.py -*- Encoding: utf-8 -*- | |
import wx | |
import gettext | |
import matplotlib | |
matplotlib.use('WXAgg') | |
from pylab import * | |
from matplotlib.backends.backend_wxagg import \ | |
FigureCanvasWxAgg as FigureCanvas | |
from matplotlib.figure import Figure | |
import matplotlib.font_manager as fm | |
fp = fm.FontProperties(fname="simhei.ttf") | |
class GraphFrame(wx.Frame): | |
def __init__(self, parent, id, title): | |
wx.Frame.__init__(self, parent, id, title, size=(650, 450)) | |
self.figure = Figure() | |
self.axes = self.figure.add_subplot(111) | |
self.axes.plot([1, 2, 4]) | |
self.axes.set_title(u"标题栏", fontproperties=fp) | |
self.axes.set_xlabel(u"X 标签", fontproperties=fp) | |
self.axes.set_ylabel(u"Y 标签", fontproperties=fp) | |
self.axes.text(0.5, 2.5, u"测试文本", rotation=45, fontproperties=fp) | |
self.axes.text(1, 1.5, u"还是文本", fontproperties=fp) | |
self.canvas = FigureCanvas(self, -1, self.figure) | |
self.sizer = wx.BoxSizer(wx.VERTICAL) | |
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) | |
self.SetSizer(self.sizer) | |
self.Fit() | |
class MyApp(wx.App): | |
def OnInit(self): | |
frame = GraphFrame(None, -1, u"图表") | |
self.SetTopWindow(frame) | |
frame.CentreOnScreen() | |
frame.Show(True) | |
return True | |
def main(): | |
app = MyApp() | |
app.MainLoop() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment