Skip to content

Commit d693225

Browse files
committed
QwtPlot: added "flatStyle" option
This is a PythonQwt-exclusive feature improving default plot style (without margin, more compact and flat look) -- option is enabled by default
1 parent 5c101bf commit d693225

5 files changed

Lines changed: 68 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# PythonQwt Releases #
22

33

4-
### Version 0.6.3 ###
4+
### Version 0.7.0 ###
55

6+
- QwtPlot: added "flatStyle" option, a PythonQwt-exclusive feature improving
7+
default plot style (without margin, more compact and flat look) -- option is
8+
enabled by default
69
- Fixed obvious errors (+ poor implementations) in untested code parts
710

811

qwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
.. _GitHubPage: http://pierreraybaut.github.io/PythonQwt
2929
.. _GitHub: https://github.com/PierreRaybaut/PythonQwt
3030
"""
31-
__version__ = '0.6.3'
31+
__version__ = '0.7.0'
3232
QWT_VERSION_STR = '6.1.5'
3333

3434
import warnings

qwt/plot.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
from .qt.QtGui import (QWidget, QFont, QSizePolicy, QFrame, QApplication,
23-
QPainter, QPalette)
23+
QPainter, QPalette, QColor)
2424
from .qt.QtCore import Qt, Signal, QEvent, QSize, QRectF
2525

2626
from .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

197198
class 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

qwt/tests/CartesianDemo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def __init__(self, *args):
6262
# attach a grid
6363
grid = QwtPlotGrid()
6464
grid.attach(self)
65-
grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
65+
grid.setPen(QPen(Qt.lightGray, 0, Qt.DotLine))
66+
grid.setZ(-1)
6667
# attach a x-axis
6768
xaxis = CartesianAxis(QwtPlot.xBottom, QwtPlot.yLeft)
6869
xaxis.attach(self)
@@ -83,11 +84,11 @@ def __init__(self, *args):
8384
# attach another curve
8485
curve = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2')
8586
curve.attach(self)
86-
curve.setPen(QPen(Qt.black, 2))
87+
curve.setPen(QPen(Qt.blue, 2))
8788
curve.setData(x, z)
8889
self.replot()
8990

9091

9192
if __name__ == '__main__':
9293
from qwt.tests import test_widget
93-
test_widget(CartesianPlot, (400, 300))
94+
test_widget(CartesianPlot, (800, 480))

qwt/tests/no_margin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, parent=None):
5454
ticks_font = self.axisFont(axis_id)
5555
self.setAxisFont(axis_id, ticks_font)
5656

57-
self.canvas().setFrameStyle(0)#QFrame.Panel|QFrame.Sunken)
57+
self.canvas().setFrameStyle(0)
5858
self.plotLayout().setCanvasMargin(0)
5959
self.axisWidget(QwtPlot.yLeft).setMargin(0)
6060
self.axisWidget(QwtPlot.xTop).setMargin(0)

0 commit comments

Comments
 (0)