wxPython+Matplotlib繪制折線圖表
更新時(shí)間:2019年11月19日 14:45:06 作者:百家曉東
這篇文章主要介紹了wxPython+Matplotlib繪制折線圖表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
使用Matplotlib在wxPython的Panel上繪制曲線圖,需要導(dǎo)入:
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'第一個(gè)窗口', pos=(10, 10), size=(340, 550), style=style)
self.frame.Show()
return True
def main():
app = MainApp()
app.MainLoop()
if __name__ == "__main__":
main()
效果:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- python使用matplotlib繪制折線圖教程
- python使用matplotlib模塊繪制多條折線圖、散點(diǎn)圖
- Python可視化Matplotlib折線圖plot用法詳解
- python使用matplotlib繪制折線圖
- Python基于Matplotlib庫簡單繪制折線圖的方法示例
- 教你利用python的matplotlib(pyplot)繪制折線圖和柱狀圖
- python學(xué)習(xí)之使用Matplotlib畫實(shí)時(shí)的動(dòng)態(tài)折線圖的示例代碼
- python matplotlib折線圖樣式實(shí)現(xiàn)過程
- Python利用matplotlib繪制折線圖的新手教程
- Python?matplotlib之折線圖的各種樣式與畫法總結(jié)
相關(guān)文章
Python實(shí)現(xiàn)iOS自動(dòng)化打包詳解步驟
這篇文章主要介紹了Python實(shí)現(xiàn)iOS自動(dòng)化打包詳解步驟,文中通過示例代碼以及圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
Python RPA自動(dòng)化機(jī)器人模擬鼠標(biāo)鍵盤
這篇文章主要介紹了Python RPA自動(dòng)化機(jī)器人模擬鼠標(biāo)鍵盤,RPA,全稱為Robotic Process Automation,即機(jī)器人流程自動(dòng)化。我們可以利用RPA技術(shù)將工作中可重復(fù)的部分流程化,讓機(jī)器替我們完成這一工作2023-02-02
python3+PyQt5使用數(shù)據(jù)庫表視圖
這篇文章主要為大家詳細(xì)介紹了python3+PyQt5使用數(shù)據(jù)庫表視圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
徹底卸載Anaconda詳細(xì)教程(超詳細(xì)!)
這篇文章主要給大家介紹了關(guān)于徹底卸載Anaconda的相關(guān)資料,Anaconda(官方網(wǎng)站)就是可以便捷獲取包且對(duì)包能夠進(jìn)行管理,同時(shí)對(duì)環(huán)境可以統(tǒng)一管理的發(fā)行版本,需要的朋友可以參考下2023-11-11

