@@ -101,6 +101,7 @@ def __init__(self):
101101 self .scaleDiv = None # QwtScaleDiv
102102 self .scaleEngine = None # QwtScaleEngine
103103 self .scaleWidget = None # QwtScaleWidget
104+ self .margin = None # Margin (float) in %
104105
105106
106107class QwtPlot (QFrame ):
@@ -431,6 +432,7 @@ def initAxesData(self):
431432 d .scaleWidget .setTitle (text )
432433
433434 d .doAutoScale = True
435+ d .margin = 0.05
434436 d .minValue = 0.0
435437 d .maxValue = 1000.0
436438 d .stepSize = 0.0
@@ -586,6 +588,19 @@ def axisStepSize(self, axisId):
586588 else :
587589 return 0
588590
591+ def axisMargin (self , axisId ):
592+ """
593+ :param int axisId: Axis index
594+ :return: Margin in % of the canvas size
595+
596+ .. seealso::
597+
598+ :py:meth:`setAxisMargin()`
599+ """
600+ if self .axisValid (axisId ):
601+ return self .__axisData [axisId ].margin
602+ return 0.0
603+
589604 def axisInterval (self , axisId ):
590605 """
591606 :param int axisId: Axis index
@@ -857,6 +872,24 @@ def setAxisMaxMajor(self, axisId, maxMajor):
857872 d .isValid = False
858873 self .autoRefresh ()
859874
875+ def setAxisMargin (self , axisId , margin ):
876+ """
877+ Set the margin of the scale widget
878+
879+ :param int axisId: Axis index
880+ :param float margin: Margin in % of the canvas size
881+
882+ .. seealso::
883+
884+ :py:meth:`axisMargin()`
885+ """
886+ if self .axisValid (axisId ):
887+ d = self .__axisData [axisId ]
888+ if margin != d .margin :
889+ d .margin = margin
890+ d .isValid = False
891+ self .autoRefresh ()
892+
860893 def setAxisTitle (self , axisId , title ):
861894 """
862895 Change the title of a specified axis
@@ -910,15 +943,20 @@ def updateAxes(self):
910943 intv [item .xAxis ()] |= QwtInterval (rect .left (), rect .right ())
911944 if rect .height () >= 0.0 :
912945 intv [item .yAxis ()] |= QwtInterval (rect .top (), rect .bottom ())
946+
913947 for axisId in self .AXES :
914948 d = self .__axisData [axisId ]
915949 minValue = d .minValue
916950 maxValue = d .maxValue
917951 stepSize = d .stepSize
918- if d .doAutoScale and intv [axisId ].isValid ():
952+ if d .margin is not None :
953+ intv_i = intv [axisId ].extend_fraction (d .margin )
954+ else :
955+ intv_i = intv [axisId ]
956+ if d .doAutoScale and intv_i .isValid ():
919957 d .isValid = False
920- minValue = intv [ axisId ] .minValue ()
921- maxValue = intv [ axisId ] .maxValue ()
958+ minValue = intv_i .minValue ()
959+ maxValue = intv_i .maxValue ()
922960 d .scaleEngine .autoScale (d .maxMajor , minValue , maxValue , stepSize )
923961 if not d .isValid :
924962 d .scaleDiv = d .scaleEngine .divideScale (
0 commit comments