Home > other >  Matplotlib pyqt5 drawing don't refresh the problem, a great god for help
Matplotlib pyqt5 drawing don't refresh the problem, a great god for help

Time:11-28

A, drawing class
The class DrawCanvas (FigureCanvas) :
Def __init__ (self, parent=None, width=1, height=1, dpi=1) :
# set Chinese show
PLT. RcParams ['. The font family]=[' SimHei]
PLT. RcParams [' axes. Unicode_minus]=False

# to create a new graphics object
Self. FIG=PLT. Figure (the clear=True)
The self. The axes=self. FIG. Add_subplot ()
FigureCanvas. __init__ (self, self. FIG)

Def draw_pie (self, IP data) :
Label=[" free ", "used"]
The self. The axes. Set_title (IP + "memory usage")
The self. The axes. The pie (x=data, labels=label, autopct='%. 1 f % %')
The self. The axes. The grid (True)

Def draw_colum (self, IP data) :
The self. The axes. Set_title (IP + "CPU")
# set the axis percentage change
Def to_percent (temp, position) :
Return '% 1.0 f % temp +' % '
Width=0.5
1 X=[" 5 s ", "m", "5 m"]
Self. Axes. Bar (X, data, width, label="CPU")
The self. The axes. Yaxis. Set_major_formatter (FuncFormatter (to_percent))
The self. The axes. The grid (True)

Second, Qt interface


Interface widget controls both the drawing class promotion

Three, button calling code
Def display_info (self) :
# Telnet return a dictionary info {' mem: float, 'CPU' : [], 'vlan: STR,' ontime: STR}
The self. The info=telnet_h3c_5560_552 (self. IP, the self. The pw, self. Xingh)
# according to the different type, memory usage and spare quantity order
If (self. Xingh=="S5560" or self. Xingh=="S6520") :
Self. Mem=[self. Info [" mem "]/100, the float (Decimal (STR) (100) - a Decimal (STR (self) info [" mem "])))/100]
The else:
Self. Mem=[float (Decimal (STR) (100) - a Decimal (STR (self) info/mem ")))/100, the self. The info "mem"]/100
# show hidden widget initialization time control
Self. Widget_mem. SetVisible (True)
Self. Widget_cpu. SetVisible (True)
# memory usage
Self. Widget_mem. MPL. Axes. Cla ()
Self. Widget_mem. MPL. Draw_pie (self. IP, the self. The mem)
# CPU usage
Self. Widget_cpu. MPL. Axes. Cla ()
Self. Widget_cpu. MPL. Draw_colum (self. IP, the self. The info [" CPU "])
# show vlan information
The self. The label. The setVisible (True)
Self. Label_vlan. SetText (self. Info [" vlan "])
The # show online time
Self. Label_4. SetVisible (True)
Self. Label_time. SetText (self. Info [" ontime "])

Four, intentions and problems
I just want to according to different device interface on the right side of the information input, click ok button, on the left to display different information, why do you paint a equipment of figure I choose the second, and then click ok, other information will refresh, but the two figures on a device or information? A great god, please grant instruction,
  • Related