Skip to content

Commit 41a2064

Browse files
committed
Added "plot without margins" test for Issue #35
1 parent 4901c4c commit 41a2064

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

qwt/tests/no_margin.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the MIT License
4+
# Copyright (c) 2015 Pierre Raybaut
5+
# (see LICENSE file for more details)
6+
7+
"""Simple plot without margins"""
8+
9+
SHOW = True # Show test in GUI-based test launcher
10+
11+
import numpy as np
12+
13+
from qwt.qt.QtGui import QApplication, QFont, QPen, QPalette, QColor
14+
from qwt.qt.QtCore import Qt
15+
16+
import os
17+
if os.environ.get('USE_PYQWT5', True):
18+
USE_PYQWT5 = True
19+
from PyQt4.Qwt5 import QwtPlot, QwtPlotCurve, QwtPlotMarker, QwtText
20+
else:
21+
USE_PYQWT5 = False
22+
from qwt import QwtPlot, QwtPlotCurve, QwtPlotMarker, QwtText # analysis:ignore
23+
24+
25+
class TestPlot(QwtPlot):
26+
def __init__(self, parent=None):
27+
super(TestPlot, self).__init__(parent)
28+
self.setWindowTitle("PyQwt" if USE_PYQWT5 else "PythonQwt")
29+
self.enableAxis(self.xTop, True)
30+
self.enableAxis(self.yRight, True)
31+
y = np.linspace(0, 10, 500)
32+
curve1 = QwtPlotCurve('Test Curve 1')
33+
curve1.setData(np.sin(y), y)
34+
curve2 = QwtPlotCurve('Test Curve 2')
35+
curve2.setData(y**3, y)
36+
if USE_PYQWT5:
37+
curve2.setAxis(self.xTop, self.yRight)
38+
else:
39+
# PythonQwt
40+
curve2.setAxes(self.xTop, self.yRight)
41+
42+
for item, col, xa, ya in ((curve1, Qt.green, self.xBottom, self.yLeft),
43+
(curve2, Qt.red, self.xTop, self.yRight)):
44+
if not USE_PYQWT5:
45+
# PythonQwt
46+
item.setOrientation(Qt.Vertical)
47+
item.attach(self)
48+
item.setPen(QPen(col))
49+
for axis_id in xa, ya:
50+
palette = self.axisWidget(axis_id).palette()
51+
palette.setColor(QPalette.WindowText, QColor(col))
52+
palette.setColor(QPalette.Text, QColor(col))
53+
self.axisWidget(axis_id).setPalette(palette)
54+
ticks_font = self.axisFont(axis_id)
55+
self.setAxisFont(axis_id, ticks_font)
56+
57+
self.canvas().setFrameStyle(0)#QFrame.Panel|QFrame.Sunken)
58+
self.plotLayout().setCanvasMargin(0)
59+
self.axisWidget(QwtPlot.yLeft).setMargin(0)
60+
self.axisWidget(QwtPlot.xTop).setMargin(0)
61+
self.axisWidget(QwtPlot.yRight).setMargin(0)
62+
self.axisWidget(QwtPlot.xBottom).setMargin(0)
63+
64+
self.marker = QwtPlotMarker()
65+
self.marker.setValue(0, 5)
66+
self.marker.attach(self)
67+
68+
def resizeEvent(self, event):
69+
super(TestPlot, self).resizeEvent(event)
70+
self.show_layout_details()
71+
72+
def show_layout_details(self):
73+
text = QwtText(
74+
"plotLayout().canvasRect():\n%r\n\n"
75+
"canvas().geometry():\n%r\n\n"
76+
"plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n"
77+
"axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n"
78+
"plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n"
79+
"axisWidget(QwtPlot.yRight).geometry():\n%r\n\n"
80+
"plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n"
81+
"axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n"
82+
"plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n"
83+
"axisWidget(QwtPlot.xTop).geometry():\n%r\n\n"
84+
% (self.plotLayout().canvasRect().getCoords(),
85+
self.canvas().geometry().getCoords(),
86+
self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(),
87+
self.axisWidget(QwtPlot.yLeft).geometry().getCoords(),
88+
self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(),
89+
self.axisWidget(QwtPlot.yRight).geometry().getCoords(),
90+
self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(),
91+
self.axisWidget(QwtPlot.xBottom).geometry().getCoords(),
92+
self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(),
93+
self.axisWidget(QwtPlot.xTop).geometry().getCoords(),
94+
)
95+
)
96+
text.setFont(QFont('Courier New'))
97+
text.setColor(Qt.blue)
98+
self.marker.setLabel(text)
99+
100+
if __name__ == '__main__':
101+
app = QApplication([])
102+
plot = TestPlot()
103+
plot.resize(300, 1000)
104+
plot.show()
105+
app.exec_()

0 commit comments

Comments
 (0)