2020"""
2121
2222from .qt .QtGui import (QWidget , QFont , QSizePolicy , QFrame , QApplication ,
23- QPainter , QPalette )
23+ QPainter , QPalette , QColor )
2424from .qt .QtCore import Qt , Signal , QEvent , QSize , QRectF
2525
2626from .text import QwtText , QwtTextLabel
@@ -192,6 +192,7 @@ def __init__(self):
192192 self .legend = None
193193 self .layout = None
194194 self .autoReplot = None
195+ self .flatStyle = None
195196
196197
197198class AxisData (object ):
@@ -309,7 +310,7 @@ def __init__(self, *args):
309310 self .__data .autoReplot = False
310311
311312 self .setAutoReplot (True )
312- # self.setPlotLayout(self.__data.layout)
313+ self .setPlotLayout (self .__data .layout )
313314
314315 # title
315316 self .__data .titleLabel = QwtTextLabel (self )
@@ -338,6 +339,8 @@ def __init__(self, *args):
338339 self .__data .canvas = QwtPlotCanvas (self )
339340 self .__data .canvas .setObjectName ("QwtPlotCanvas" )
340341 self .__data .canvas .installEventFilter (self )
342+
343+ self .setFlatStyle (True )
341344
342345 self .setSizePolicy (QSizePolicy .MinimumExpanding ,
343346 QSizePolicy .MinimumExpanding )
@@ -972,7 +975,7 @@ def setAutoReplot(self, tf=True):
972975
973976 .. seealso::
974977
975- :py:meth:`canvas ()`
978+ :py:meth:`autoReplot ()`
976979 """
977980 self .__data .autoReplot = tf
978981
@@ -986,6 +989,58 @@ def autoReplot(self):
986989 """
987990 return self .__data .autoReplot
988991
992+ def setFlatStyle (self , state ):
993+ """
994+ Set or reset the flatStyle option
995+
996+ If the flatStyle option is set, the plot will be
997+ rendered without any margin (scales, canvas, layout).
998+
999+ Enabling this option makes the plot look flat and compact.
1000+
1001+ The flatStyle option is set to True by default.
1002+
1003+ :param bool state: True or False.
1004+
1005+ .. seealso::
1006+
1007+ :py:meth:`flatStyle()`
1008+ """
1009+ if state :
1010+ self .canvas ().setFrameStyle (QFrame .NoFrame )
1011+ self .plotLayout ().setCanvasMargin (0 )
1012+ self .plotLayout ().setSpacing (0 )
1013+ palette = self .palette ()
1014+ palette .setColor (QPalette .WindowText , QColor (Qt .darkGray ))
1015+ palette .setColor (QPalette .Text , QColor ("#444444" ))
1016+ self .setPalette (palette )
1017+ for axis_id in self .validAxes :
1018+ self .axisWidget (axis_id ).setMargin (0 )
1019+ self .axisWidget (axis_id ).setSpacing (0 )
1020+ # self.axisWidget(axis_id).setBorderDist(0, 0)
1021+ else :
1022+ self .canvas ().setFrameStyle (QFrame .Panel | QFrame .Sunken )
1023+ self .plotLayout ().setCanvasMargin (4 )
1024+ self .plotLayout ().setSpacing (5 )
1025+ palette = self .palette ()
1026+ palette .setColor (QPalette .WindowText , QColor (Qt .black ))
1027+ palette .setColor (QPalette .Text , QColor (Qt .black ))
1028+ self .setPalette (palette )
1029+ for axis_id in self .validAxes :
1030+ self .axisWidget (axis_id ).setMargin (2 )
1031+ self .axisWidget (axis_id ).setSpacing (2 )
1032+ self .__data .flatStyle = state
1033+
1034+ def flatStyle (self ):
1035+ """
1036+ :return: True if the flatStyle option is set.
1037+
1038+ .. seealso::
1039+
1040+ :py:meth:`setFlatStyle()`
1041+ """
1042+ return self .__data .flatStyle
1043+
9891044 def setTitle (self , title ):
9901045 """
9911046 Change the plot's title
0 commit comments