明霞山资源网 Design By www.htccd.com
使用Matplotlib在wxPython的Panel上绘制曲线图,需要导入:
import numpy from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.figure import Figure
下面直接贴出源代码:
#coding=utf-8
"""
程序的主入口
"""
import wx
import numpy
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class FirseFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='', pos=wx.DefaultSize, size=wx.DefaultSize, style= wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.InitUI()
pass
def InitUI(self):
self.SetBackgroundColour('white')
self.scorePanel = wx.Panel(self)
scores = [89, 98, 70, 80, 60, 78, 85, 90]
sum = 0
for s in scores:
sum += s
average = sum / len(scores)
t_score = numpy.arange(1, len(scores) + 1, 1)
s_score = numpy.array(scores)
self.figure_score = Figure()
self.figure_score.set_figheight(3.6)
self.figure_score.set_figwidth(7.8)
self.axes_score = self.figure_score.add_subplot(111)
self.axes_score.plot(t_score, s_score, 'ro', t_score, s_score, 'k')
self.axes_score.axhline(y=average, color='r')
self.axes_score.set_title(u'My Scores')
self.axes_score.grid(True)
self.axes_score.set_xlabel('T')
self.axes_score.set_ylabel('score')
FigureCanvas(self.scorePanel, -1, self.figure_score)
pass
class MainApp(wx.App):
def OnInit(self):
style = wx.DEFAULT_FRAME_STYLE^wx.MAXIMIZE_BOX
self.frame = FirseFrame(id=-1, title=u'第一个窗口', pos=(10, 10), size=(340, 550), style=style)
self.frame.Show()
return True
def main():
app = MainApp()
app.MainLoop()
if __name__ == "__main__":
main()
效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
