/usr/lib/python3/dist-packages/qwt/plot.py is in python3-qwt 0.5.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 | # -*- coding: utf-8 -*-
#
# Licensed under the terms of the Qwt License
# Copyright (c) 2002 Uwe Rathmann, for the original C++ code
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
# (see LICENSE file for more details)
"""
QwtPlot
-------
.. autoclass:: QwtPlot
:members:
QwtPlotItem
-----------
.. autoclass:: QwtPlotItem
:members:
"""
from qwt.qt.QtGui import (QWidget, QFont, QSizePolicy, QFrame, QApplication,
QRegion, QPainter, QPalette)
from qwt.qt.QtCore import Qt, Signal, QEvent, QSize, QRectF
from qwt.text import QwtText, QwtTextLabel
from qwt.scale_widget import QwtScaleWidget
from qwt.scale_draw import QwtScaleDraw
from qwt.scale_engine import QwtLinearScaleEngine
from qwt.plot_canvas import QwtPlotCanvas
from qwt.scale_div import QwtScaleDiv
from qwt.scale_map import QwtScaleMap
from qwt.graphic import QwtGraphic
from qwt.legend import QwtLegendData
from qwt.interval import QwtInterval
import numpy as np
def qwtEnableLegendItems(plot, on):
if on:
plot.legendDataChanged.connect(plot.updateLegendItems)
else:
plot.legendDataChanged.disconnect(plot.updateLegendItems)
def qwtSetTabOrder(first, second, with_children):
tab_chain = [first, second]
if with_children:
children = second.findChildren(QWidget)
w = second.nextInFocusChain()
while w in children:
while w in children:
children.remove(w)
tab_chain += [w]
w = w.nextInFocusChain()
for idx in range(len(tab_chain)-1):
w_from = tab_chain[idx]
w_to = tab_chain[idx+1]
policy1, policy2 = w_from.focusPolicy(), w_to.focusPolicy()
proxy1, proxy2 = w_from.focusProxy(), w_to.focusProxy()
for w in (w_from, w_to):
w.setFocusPolicy(Qt.TabFocus)
w.setFocusProxy(None)
QWidget.setTabOrder(w_from, w_to)
for w, pl, px in ((w_from, policy1, proxy1), (w_to, policy2, proxy2)):
w.setFocusPolicy(pl)
w.setFocusProxy(px)
class ItemList(list):
def sortItems(self):
self.sort(key=lambda item: item.z())
def insertItem(self, obj):
self.append(obj)
self.sortItems()
def removeItem(self, obj):
self.remove(obj)
self.sortItems()
class QwtPlotDict_PrivateData(object):
def __init__(self):
self.itemList = ItemList()
self.autoDelete = True
class QwtPlotDict(object):
"""
A dictionary for plot items
`QwtPlotDict` organizes plot items in increasing z-order.
If `autoDelete()` is enabled, all attached items will be deleted
in the destructor of the dictionary.
`QwtPlotDict` can be used to get access to all `QwtPlotItem` items - or
all items of a specific type - that are currently on the plot.
.. seealso::
:py:meth:`QwtPlotItem.attach()`, :py:meth:`QwtPlotItem.detach()`,
:py:meth:`QwtPlotItem.z()`
"""
def __init__(self):
self.__data = QwtPlotDict_PrivateData()
def setAutoDelete(self, autoDelete):
"""
En/Disable Auto deletion
If Auto deletion is on all attached plot items will be deleted
in the destructor of `QwtPlotDict`. The default value is on.
:param bool autoDelete: enable/disable
.. seealso::
:py:meth:`autoDelete()`, :py:meth:`insertItem()`
"""
self.__data.autoDelete = autoDelete
def autoDelete(self):
"""
:return: true if auto deletion is enabled
.. seealso::
:py:meth:`setAutoDelete()`, :py:meth:`insertItem()`
"""
return self.__data.autoDelete
def insertItem(self, item):
"""
Insert a plot item
:param qwt.plot.QwtPlotItem item: PlotItem
.. seealso::
:py:meth:`removeItem()`
"""
self.__data.itemList.insertItem(item)
def removeItem(self, item):
"""
Remove a plot item
:param qwt.plot.QwtPlotItem item: PlotItem
.. seealso::
:py:meth:`insertItem()`
"""
self.__data.itemList.removeItem(item)
def detachItems(self, rtti, autoDelete):
"""
Detach items from the dictionary
:param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
:param bool autoDelete: If true, delete all detached items
"""
for item in self.__data.itemList[:]:
if rtti == QwtPlotItem.Rtti_PlotItem and item.rtti() == rtti:
item.attach(None)
if self.autoDelete:
self.__data.itemList.remove(item)
def itemList(self, rtti=None):
"""
A list of attached plot items.
Use caution when iterating these lists, as removing/detaching an
item will invalidate the iterator. Instead you can place pointers
to objects to be removed in a removal list, and traverse that list
later.
:param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
:return: List of all attached plot items of a specific type. If rtti is None, return a list of all attached plot items.
"""
if rtti is None or rtti == QwtPlotItem.Rtti_PlotItem:
return self.__data.itemList
return [item for item in self.__data.itemList if item.rtti() == rtti]
class QwtPlot_PrivateData(QwtPlotDict_PrivateData):
def __init__(self):
super(QwtPlot_PrivateData, self).__init__()
self.titleLabel = None
self.footerLabel = None
self.canvas = None
self.legend = None
self.layout = None
self.autoReplot = None
class AxisData(object):
def __init__(self):
self.isEnabled = None
self.doAutoScale = None
self.minValue = None
self.maxValue = None
self.stepSize = None
self.maxMajor = None
self.maxMinor = None
self.isValid = None
self.scaleDiv = None # QwtScaleDiv
self.scaleEngine = None # QwtScaleEngine
self.scaleWidget = None # QwtScaleWidget
class QwtPlot(QFrame, QwtPlotDict):
"""
A 2-D plotting widget
QwtPlot is a widget for plotting two-dimensional graphs.
An unlimited number of plot items can be displayed on its canvas.
Plot items might be curves (:py:class:`qwt.plot_curve.QwtPlotCurve`),
markers (:py:class:`qwt.plot_marker.QwtPlotMarker`),
the grid (:py:class:`qwt.plot_grid.QwtPlotGrid`), or anything else
derived from :py:class:`QwtPlotItem`.
A plot can have up to four axes, with each plot item attached to an x- and
a y axis. The scales at the axes can be explicitly set (`QwtScaleDiv`), or
are calculated from the plot items, using algorithms (`QwtScaleEngine`)
which can be configured separately for each axis.
The following example is a good starting point to see how to set up a
plot widget::
from qwt.qt.QtGui import QApplication
from qwt import QwtPlot, QwtPlotCurve
import numpy as np
app = QApplication([])
x = np.linspace(-10, 10, 500)
y1, y2 = np.cos(x), np.sin(x)
my_plot = QwtPlot("Two curves")
curve1, curve2 = QwtPlotCurve("Curve 1"), QwtPlotCurve("Curve 2")
curve1.setData(x, y1)
curve2.setData(x, y2)
curve1.attach(my_plot)
curve2.attach(my_plot)
my_plot.resize(600, 300)
my_plot.replot()
my_plot.show()
app.exec_()
.. image:: /images/QwtPlot_example.png
.. py:class:: QwtPlot([title=""], [parent=None])
:param str title: Title text
:param QWidget parent: Parent widget
.. py:data:: itemAttached
A signal indicating, that an item has been attached/detached
:param plotItem: Plot item
:param on: Attached/Detached
.. py:data:: legendDataChanged
A signal with the attributes how to update
the legend entries for a plot item.
:param itemInfo: Info about a plot item, build from itemToInfo()
:param data: Attributes of the entries (usually <= 1) for the plot item.
"""
itemAttached = Signal("PyQt_PyObject", bool)
legendDataChanged = Signal("PyQt_PyObject", "PyQt_PyObject")
# enum Axis
validAxes = yLeft, yRight, xBottom, xTop = list(range(4))
axisCnt = len(validAxes)
# enum LegendPosition
LeftLegend, RightLegend, BottomLegend, TopLegend = list(range(4))
def __init__(self, *args):
if len(args) == 0:
title, parent = "", None
elif len(args) == 1:
if isinstance(args[0], QWidget) or args[0] is None:
title = ""
parent, = args
else:
title, = args
parent = None
elif len(args) == 2:
title, parent = args
else:
raise TypeError("%s() takes 0, 1 or 2 argument(s) (%s given)"\
% (self.__class__.__name__, len(args)))
QwtPlotDict.__init__(self)
QFrame.__init__(self, parent)
self.__layout_state = None
self.__data = QwtPlot_PrivateData()
from qwt.plot_layout import QwtPlotLayout
self.__data.layout = QwtPlotLayout()
self.__data.autoReplot = False
self.setAutoReplot(True)
# self.setPlotLayout(self.__data.layout)
# title
self.__data.titleLabel = QwtTextLabel(self)
self.__data.titleLabel.setObjectName("QwtPlotTitle")
self.__data.titleLabel.setFont(QFont(self.fontInfo().family(), 14,
QFont.Bold))
text = QwtText(title)
text.setRenderFlags(Qt.AlignCenter|Qt.TextWordWrap)
self.__data.titleLabel.setText(text)
# footer
self.__data.footerLabel = QwtTextLabel(self)
self.__data.footerLabel.setObjectName("QwtPlotFooter")
footer = QwtText()
footer.setRenderFlags(Qt.AlignCenter|Qt.TextWordWrap)
self.__data.footerLabel.setText(footer)
# legend
self.__data.legend = None
# axis
self.__axisData = []
self.initAxesData()
# canvas
self.__data.canvas = QwtPlotCanvas(self)
self.__data.canvas.setObjectName("QwtPlotCanvas")
self.__data.canvas.installEventFilter(self)
self.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.MinimumExpanding)
self.resize(200, 200)
focusChain = [self, self.__data.titleLabel, self.axisWidget(self.xTop),
self.axisWidget(self.yLeft), self.__data.canvas,
self.axisWidget(self.yRight),
self.axisWidget(self.xBottom), self.__data.footerLabel]
for idx in range(len(focusChain)-1):
qwtSetTabOrder(focusChain[idx], focusChain[idx+1], False)
qwtEnableLegendItems(self, True)
def __del__(self):
#XXX Is is really necessary in Python? (pure transcription of C++)
self.setAutoReplot(False)
self.detachItems(QwtPlotItem.Rtti_PlotItem, self.autoDelete())
self.__data.layout = None
self.deleteAxesData()
self.__data = None
def initAxesData(self):
"""Initialize axes"""
self.__axisData = [AxisData() for axisId in self.validAxes]
self.__axisData[self.yLeft].scaleWidget = \
QwtScaleWidget(QwtScaleDraw.LeftScale, self)
self.__axisData[self.yRight].scaleWidget = \
QwtScaleWidget(QwtScaleDraw.RightScale, self)
self.__axisData[self.xTop].scaleWidget = \
QwtScaleWidget(QwtScaleDraw.TopScale, self)
self.__axisData[self.xBottom].scaleWidget = \
QwtScaleWidget(QwtScaleDraw.BottomScale, self)
self.__axisData[self.yLeft
].scaleWidget.setObjectName("QwtPlotAxisYLeft")
self.__axisData[self.yRight
].scaleWidget.setObjectName("QwtPlotAxisYRight")
self.__axisData[self.xTop
].scaleWidget.setObjectName("QwtPlotAxisXTop")
self.__axisData[self.xBottom
].scaleWidget.setObjectName("QwtPlotAxisXBottom")
fscl = QFont(self.fontInfo().family(), 10)
fttl = QFont(self.fontInfo().family(), 12, QFont.Bold)
for axisId in self.validAxes:
d = self.__axisData[axisId]
d.scaleEngine = QwtLinearScaleEngine()
d.scaleWidget.setTransformation(d.scaleEngine.transformation())
d.scaleWidget.setFont(fscl)
d.scaleWidget.setMargin(2)
text = d.scaleWidget.title()
text.setFont(fttl)
d.scaleWidget.setTitle(text)
d.doAutoScale = True
d.minValue = 0.0
d.maxValue = 1000.0
d.stepSize = 0.0
d.maxMinor = 5
d.maxMajor = 8
d.isValid = False
self.__axisData[self.yLeft].isEnabled = True
self.__axisData[self.yRight].isEnabled = False
self.__axisData[self.xBottom].isEnabled = True
self.__axisData[self.xTop].isEnabled = False
def deleteAxesData(self):
#XXX Is is really necessary in Python? (pure transcription of C++)
for axisId in self.validAxes:
self.__axisData[axisId].scaleEngine = None
self.__axisData[axisId] = None
def axisWidget(self, axisId):
"""
:param int axisId: Axis index
:return: Scale widget of the specified axis, or None if axisId is invalid.
"""
if self.axisValid(axisId):
return self.__axisData[axisId].scaleWidget
def setAxisScaleEngine(self, axisId, scaleEngine):
"""
Change the scale engine for an axis
:param int axisId: Axis index
:param qwt.scale_engine.QwtScaleEngine scaleEngine: Scale engine
.. seealso::
:py:meth:`axisScaleEngine()`
"""
if self.axisValid(axisId) and scaleEngine is not None:
d = self.__axisData[axisId]
d.scaleEngine = scaleEngine
self.__axisData[axisId].scaleWidget.setTransformation(
scaleEngine.transformation())
d.isValid = False
self.autoRefresh()
def axisScaleEngine(self, axisId):
"""
:param int axisId: Axis index
:return: Scale engine for a specific axis
.. seealso::
:py:meth:`setAxisScaleEngine()`
"""
if self.axisValid(axisId):
return self.__axisData[axisId].scaleEngine
def axisAutoScale(self, axisId):
"""
:param int axisId: Axis index
:return: True, if autoscaling is enabled
"""
if self.axisValid(axisId):
return self.__axisData[axisId].doAutoScale
def axisEnabled(self, axisId):
"""
:param int axisId: Axis index
:return: True, if a specified axis is enabled
"""
if self.axisValid(axisId):
return self.__axisData[axisId].isEnabled
def axisFont(self, axisId):
"""
:param int axisId: Axis index
:return: The font of the scale labels for a specified axis
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).font()
else:
return QFont()
def axisMaxMajor(self, axisId):
"""
:param int axisId: Axis index
:return: The maximum number of major ticks for a specified axis
.. seealso::
:py:meth:`setAxisMaxMajor()`,
:py:meth:`qwt.scale_engine.QwtScaleEngine.divideScale()`
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).maxMajor
else:
return 0
def axisMaxMinor(self, axisId):
"""
:param int axisId: Axis index
:return: The maximum number of minor ticks for a specified axis
.. seealso::
:py:meth:`setAxisMaxMinor()`,
:py:meth:`qwt.scale_engine.QwtScaleEngine.divideScale()`
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).maxMinor
else:
return 0
def axisScaleDiv(self, axisId):
"""
:param int axisId: Axis index
:return: The scale division of a specified axis
axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound()
are the current limits of the axis scale.
.. seealso::
:py:class:`qwt.scale_div.QwtScaleDiv`,
:py:meth:`setAxisScaleDiv()`,
:py:meth:`qwt.scale_engine.QwtScaleEngine.divideScale()`
"""
return self.__axisData[axisId].scaleDiv
def axisScaleDraw(self, axisId):
"""
:param int axisId: Axis index
:return: Specified scaleDraw for axis, or NULL if axis is invalid.
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).scaleDraw()
def axisStepSize(self, axisId):
"""
:param int axisId: Axis index
:return: step size parameter value
This doesn't need to be the step size of the current scale.
.. seealso::
:py:meth:`setAxisScale()`,
:py:meth:`qwt.scale_engine.QwtScaleEngine.divideScale()`
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).stepSize
else:
return 0
def axisInterval(self, axisId):
"""
:param int axisId: Axis index
:return: The current interval of the specified axis
This is only a convenience function for axisScaleDiv(axisId).interval()
.. seealso::
:py:class:`qwt.scale_div.QwtScaleDiv`,
:py:meth:`axisScaleDiv()`
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).scaleDiv.interval()
else:
return QwtInterval()
def axisTitle(self, axisId):
"""
:param int axisId: Axis index
:return: Title of a specified axis
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).title()
else:
return QwtText()
def enableAxis(self, axisId, tf=True):
"""
Enable or disable a specified axis
When an axis is disabled, this only means that it is not
visible on the screen. Curves, markers and can be attached
to disabled axes, and transformation of screen coordinates
into values works as normal.
Only xBottom and yLeft are enabled by default.
:param int axisId: Axis index
:param bool tf: True (enabled) or False (disabled)
"""
if self.axisValid(axisId) and tf != self.__axisData[axisId].isEnabled:
self.__axisData[axisId].isEnabled = tf
self.updateLayout()
def invTransform(self, axisId, pos):
"""
Transform the x or y coordinate of a position in the
drawing region into a value.
:param int axisId: Axis index
:param int pos: position
.. warning::
The position can be an x or a y coordinate,
depending on the specified axis.
"""
if self.axisValid(axisId):
return self.canvasMap(axisId).invTransform(pos)
else:
return 0.
def transform(self, axisId, value):
"""
Transform a value into a coordinate in the plotting region
:param int axisId: Axis index
:param fload value: Value
:return: X or Y coordinate in the plotting region corresponding to the value.
"""
if self.axisValid(axisId):
return self.canvasMap(axisId).transform(value)
else:
return 0.
def setAxisFont(self, axisId, font):
"""
Change the font of an axis
:param int axisId: Axis index
:param QFont font: Font
.. warning::
This function changes the font of the tick labels,
not of the axis title.
"""
if self.axisValid(axisId):
return self.axisWidget(axisId).setFont(font)
def setAxisAutoScale(self, axisId, on=True):
"""
Enable autoscaling for a specified axis
This member function is used to switch back to autoscaling mode
after a fixed scale has been set. Autoscaling is enabled by default.
:param int axisId: Axis index
:param bool on: On/Off
.. seealso::
:py:meth:`setAxisScale()`, :py:meth:`setAxisScaleDiv()`,
:py:meth:`updateAxes()`
.. note::
The autoscaling flag has no effect until updateAxes() is executed
( called by replot() ).
"""
if self.axisValid(axisId) and self.__axisData[axisId].doAutoScale != on:
self.__axisData[axisId].doAutoScale = on
self.autoRefresh()
def setAxisScale(self, axisId, min_, max_, stepSize=0):
"""
Disable autoscaling and specify a fixed scale for a selected axis.
In updateAxes() the scale engine calculates a scale division from the
specified parameters, that will be assigned to the scale widget. So
updates of the scale widget usually happen delayed with the next replot.
:param int axisId: Axis index
:param float min_: Minimum of the scale
:param float max_: Maximum of the scale
:param float stepSize: Major step size. If <code>step == 0</code>, the step size is calculated automatically using the maxMajor setting.
.. seealso::
:py:meth:`setAxisMaxMajor()`, :py:meth:`setAxisAutoScale()`,
:py:meth:`axisStepSize()`,
:py:meth:`qwt.scale_engine.QwtScaleEngine.divideScale()`
"""
if self.axisValid(axisId):
d = self.__axisData[axisId]
d.doAutoScale = False
d.isValid = False
d.minValue = min_
d.maxValue = max_
d.stepSize = stepSize
self.autoRefresh()
def setAxisScaleDiv(self, axisId, scaleDiv):
"""
Disable autoscaling and specify a fixed scale for a selected axis.
The scale division will be stored locally only until the next call
of updateAxes(). So updates of the scale widget usually happen delayed with
the next replot.
:param int axisId: Axis index
:param qwt.scale_div.QwtScaleDiv scaleDiv: Scale division
.. seealso::
:py:meth:`setAxisScale()`, :py:meth:`setAxisAutoScale()`
"""
if self.axisValid(axisId):
d = self.__axisData[axisId]
d.doAutoScale = False
d.scaleDiv = scaleDiv
d.isValid = True
self.autoRefresh()
def setAxisScaleDraw(self, axisId, scaleDraw):
"""
Set a scale draw
:param int axisId: Axis index
:param qwt.scale_draw.QwtScaleDraw scaleDraw: Object responsible for drawing scales.
By passing scaleDraw it is possible to extend QwtScaleDraw
functionality and let it take place in QwtPlot. Please note
that scaleDraw has to be created with new and will be deleted
by the corresponding QwtScale member ( like a child object ).
.. seealso::
:py:class:`qwt.scale_draw.QwtScaleDraw`,
:py:class:`qwt.scale_widget.QwtScaleWigdet`
.. warning::
The attributes of scaleDraw will be overwritten by those of the
previous QwtScaleDraw.
"""
if self.axisValid(axisId):
self.axisWidget(axisId).setScaleDraw(scaleDraw)
self.autoRefresh()
def setAxisLabelAlignment(self, axisId, alignment):
"""
Change the alignment of the tick labels
:param int axisId: Axis index
:param Qt.Alignment alignment: Or'd Qt.AlignmentFlags
.. seealso::
:py:meth:`qwt.scale_draw.QwtScaleDraw.setLabelAlignment()`
"""
if self.axisValid(axisId):
self.axisWidget(axisId).setLabelAlignment(alignment)
def setAxisLabelRotation(self, axisId, rotation):
"""
Rotate all tick labels
:param int axisId: Axis index
:param float rotation: Angle in degrees. When changing the label rotation, the label alignment might be adjusted too.
.. seealso::
:py:meth:`setLabelRotation()`, :py:meth:`setAxisLabelAlignment()`
"""
if self.axisValid(axisId):
self.axisWidget(axisId).setLabelRotation(rotation)
def setAxisLabelAutoSize(self, axisId, state):
"""
Set tick labels automatic size option (default: on)
:param int axisId: Axis index
:param bool state: On/off
.. seealso::
:py:meth:`qwt.scale_draw.QwtScaleDraw.setLabelAutoSize()`
"""
if self.axisValid(axisId):
self.axisWidget(axisId).setLabelAutoSize(state)
def setAxisMaxMinor(self, axisId, maxMinor):
"""
Set the maximum number of minor scale intervals for a specified axis
:param int axisId: Axis index
:param int maxMinor: Maximum number of minor steps
.. seealso::
:py:meth:`axisMaxMinor()`
"""
if self.axisValid(axisId):
maxMinor = max([0, min([maxMinor, 100])])
d = self.__axisData[axisId]
if maxMinor != d.maxMinor:
d.maxMinor = maxMinor
d.isValid = False
self.autoRefresh()
def setAxisMaxMajor(self, axisId, maxMajor):
"""
Set the maximum number of major scale intervals for a specified axis
:param int axisId: Axis index
:param int maxMajor: Maximum number of major steps
.. seealso::
:py:meth:`axisMaxMajor()`
"""
if self.axisValid(axisId):
maxMajor = max([1, min([maxMajor, 10000])])
d = self.__axisData[axisId]
if maxMajor != d.maxMajor:
d.maxMajor = maxMajor
d.isValid = False
self.autoRefresh()
def setAxisTitle(self, axisId, title):
"""
Change the title of a specified axis
:param int axisId: Axis index
:param title: axis title
:type title: qwt.text.QwtText or str
"""
if self.axisValid(axisId):
self.axisWidget(axisId).setTitle(title)
self.updateLayout()
def updateAxes(self):
"""
Rebuild the axes scales
In case of autoscaling the boundaries of a scale are calculated
from the bounding rectangles of all plot items, having the
`QwtPlotItem.AutoScale` flag enabled (`QwtScaleEngine.autoScale()`).
Then a scale division is calculated (`QwtScaleEngine.didvideScale()`)
and assigned to scale widget.
When the scale boundaries have been assigned with `setAxisScale()` a
scale division is calculated (`QwtScaleEngine.didvideScale()`)
for this interval and assigned to the scale widget.
When the scale has been set explicitly by `setAxisScaleDiv()` the
locally stored scale division gets assigned to the scale widget.
The scale widget indicates modifications by emitting a
`QwtScaleWidget.scaleDivChanged()` signal.
`updateAxes()` is usually called by `replot()`.
.. seealso::
:py:meth:`setAxisAutoScale()`, :py:meth:`setAxisScale()`,
:py:meth:`setAxisScaleDiv()`, :py:meth:`replot()`,
:py:meth:`QwtPlotItem.boundingRect()`
"""
intv = [QwtInterval() for _i in self.validAxes]
itmList = self.itemList()
for item in itmList:
if not item.testItemAttribute(QwtPlotItem.AutoScale):
continue
if not item.isVisible():
continue
if self.axisAutoScale(item.xAxis()) or self.axisAutoScale(item.yAxis()):
rect = item.boundingRect()
if rect.width() >= 0.:
intv[item.xAxis()] |= QwtInterval(rect.left(), rect.right())
if rect.height() >= 0.:
intv[item.yAxis()] |= QwtInterval(rect.top(), rect.bottom())
for axisId in self.validAxes:
d = self.__axisData[axisId]
minValue = d.minValue
maxValue = d.maxValue
stepSize = d.stepSize
if d.doAutoScale and intv[axisId].isValid():
d.isValid = False
minValue = intv[axisId].minValue()
maxValue = intv[axisId].maxValue()
d.scaleEngine.autoScale(d.maxMajor, minValue, maxValue, stepSize)
if not d.isValid:
d.scaleDiv = d.scaleEngine.divideScale(minValue, maxValue,
d.maxMajor, d.maxMinor, stepSize)
d.isValid = True
scaleWidget = self.axisWidget(axisId)
scaleWidget.setScaleDiv(d.scaleDiv)
# It is *really* necessary to update border dist!
# Otherwise, when tick labels are large enough, the ticks
# may not be aligned with canvas grid.
# See the following issues for more details:
# https://github.com/PierreRaybaut/guiqwt/issues/57
# https://github.com/PierreRaybaut/PythonQwt/issues/30
startDist, endDist = scaleWidget.getBorderDistHint()
scaleWidget.setBorderDist(startDist, endDist)
for item in itmList:
if item.testItemInterest(QwtPlotItem.ScaleInterest):
item.updateScaleDiv(self.axisScaleDiv(item.xAxis()),
self.axisScaleDiv(item.yAxis()))
def setCanvas(self, canvas):
"""
Set the drawing canvas of the plot widget.
The default canvas is a `QwtPlotCanvas`.
:param QWidget canvas: Canvas Widget
.. seealso::
:py:meth:`canvas()`
"""
if canvas == self.__data.canvas:
return
self.__data.canvas = canvas
if canvas is not None:
canvas.setParent(self)
canvas.installEventFilter(self)
if self.isVisible():
canvas.show()
def event(self, event):
ok = QFrame.event(self, event)
if event.type() == QEvent.LayoutRequest:
self.updateLayout()
elif event.type() == QEvent.PolishRequest:
self.replot()
return ok
def eventFilter(self, obj, event):
if obj is self.__data.canvas:
if event.type() == QEvent.Resize:
self.updateCanvasMargins()
elif event.type() == 178:#QEvent.ContentsRectChange:
self.updateLayout()
return QFrame.eventFilter(self, obj, event)
def autoRefresh(self):
"""Replots the plot if :py:meth:`autoReplot()` is True."""
if self.__data.autoReplot:
self.replot()
def setAutoReplot(self, tf=True):
"""
Set or reset the autoReplot option
If the autoReplot option is set, the plot will be
updated implicitly by manipulating member functions.
Since this may be time-consuming, it is recommended
to leave this option switched off and call :py:meth:`replot()`
explicitly if necessary.
The autoReplot option is set to false by default, which
means that the user has to call :py:meth:`replot()` in order
to make changes visible.
:param bool tf: True or False. Defaults to True.
.. seealso::
:py:meth:`canvas()`
"""
self.__data.autoReplot = tf
def autoReplot(self):
"""
:return: True if the autoReplot option is set.
.. seealso::
:py:meth:`setAutoReplot()`
"""
return self.__data.autoReplot
def setTitle(self, title):
"""
Change the plot's title
:param title: New title
:type title: str or qwt.text.QwtText
.. seealso::
:py:meth:`title()`
"""
current_title = self.__data.titleLabel.text()
if isinstance(title, QwtText) and current_title == title:
return
elif not isinstance(title, QwtText) and current_title.text() == title:
return
self.__data.titleLabel.setText(title)
self.updateLayout()
def title(self):
"""
:return: Title of the plot
.. seealso::
:py:meth:`setTitle()`
"""
return self.__data.titleLabel.text()
def titleLabel(self):
"""
:return: Title label widget.
"""
return self.__data.titleLabel
def setFooter(self, text):
"""
Change the text the footer
:param text: New text of the footer
:type text: str or qwt.text.QwtText
.. seealso::
:py:meth:`footer()`
"""
current_footer = self.__data.footerLabel.text()
if isinstance(text, QwtText) and current_footer == text:
return
elif not isinstance(text, QwtText) and current_footer.text() == text:
return
self.__data.footerLabel.setText(text)
self.updateLayout()
def footer(self):
"""
:return: Text of the footer
.. seealso::
:py:meth:`setFooter()`
"""
return self.__data.footerLabel.text()
def footerLabel(self):
"""
:return: Footer label widget.
"""
return self.__data.footerLabel
def setPlotLayout(self, layout):
"""
Assign a new plot layout
:param layout: Layout
:type layout: qwt.plot_layout.QwtPlotLayout
.. seealso::
:py:meth:`plotLayout()`
"""
if layout != self.__data.layout:
self.__data.layout = layout
self.updateLayout()
def plotLayout(self):
"""
:return: the plot's layout
.. seealso::
:py:meth:`setPlotLayout()`
"""
return self.__data.layout
def legend(self):
"""
:return: the plot's legend
.. seealso::
:py:meth:`insertLegend()`
"""
return self.__data.legend
def canvas(self):
"""
:return: the plot's canvas
"""
return self.__data.canvas
def sizeHint(self):
"""
:return: Size hint for the plot widget
.. seealso::
:py:meth:`minimumSizeHint()`
"""
dw = dh = 0
for axisId in self.validAxes:
if self.axisEnabled(axisId):
niceDist = 40
scaleWidget = self.axisWidget(axisId)
scaleDiv = scaleWidget.scaleDraw().scaleDiv()
majCnt = len(scaleDiv.ticks(QwtScaleDiv.MajorTick))
if axisId in (self.yLeft, self.yRight):
hDiff = (majCnt-1)*niceDist-scaleWidget.minimumSizeHint().height()
if hDiff > dh:
dh = hDiff
else:
wDiff = (majCnt-1)*niceDist-scaleWidget.minimumSizeHint().width()
if wDiff > dw:
dw = wDiff
return self.minimumSizeHint() + QSize(dw, dh)
def minimumSizeHint(self):
"""
:return: Return a minimum size hint
"""
hint = self.__data.layout.minimumSizeHint(self)
hint += QSize(2*self.frameWidth(), 2*self.frameWidth())
return hint
def resizeEvent(self, e):
QFrame.resizeEvent(self, e)
self.updateLayout()
def replot(self):
"""
Redraw the plot
If the `autoReplot` option is not set (which is the default)
or if any curves are attached to raw data, the plot has to
be refreshed explicitly in order to make changes visible.
.. seealso::
:py:meth:`updateAxes()`, :py:meth:`setAutoReplot()`
"""
doAutoReplot = self.autoReplot()
self.setAutoReplot(False)
self.updateAxes()
# Maybe the layout needs to be updated, because of changed
# axes labels. We need to process them here before painting
# to avoid that scales and canvas get out of sync.
QApplication.sendPostedEvents(self, QEvent.LayoutRequest)
if self.__data.canvas:
try:
self.__data.canvas.replot()
except (AttributeError, TypeError):
self.__data.canvas.update(self.__data.canvas.contentsRect())
self.setAutoReplot(doAutoReplot)
def get_layout_state(self):
return (self.contentsRect(),
self.__data.titleLabel.text(), self.__data.footerLabel.text(),
[(self.axisEnabled(axisId), self.axisTitle(axisId).text())
for axisId in self.validAxes],
self.__data.legend)
def updateLayout(self):
"""
Adjust plot content to its current size.
.. seealso::
:py:meth:`resizeEvent()`
"""
# state = self.get_layout_state()
# if self.__layout_state is not None and\
# state == self.__layout_state:
# return
# self.__layout_state = state
self.__data.layout.activate(self, self.contentsRect())
titleRect = self.__data.layout.titleRect().toRect()
footerRect = self.__data.layout.footerRect().toRect()
scaleRect = [self.__data.layout.scaleRect(axisId).toRect()
for axisId in self.validAxes]
legendRect = self.__data.layout.legendRect().toRect()
canvasRect = self.__data.layout.canvasRect().toRect()
if self.__data.titleLabel.text():
self.__data.titleLabel.setGeometry(titleRect)
if not self.__data.titleLabel.isVisibleTo(self):
self.__data.titleLabel.show()
else:
self.__data.titleLabel.hide()
if self.__data.footerLabel.text():
self.__data.footerLabel.setGeometry(footerRect)
if not self.__data.footerLabel.isVisibleTo(self):
self.__data.footerLabel.show()
else:
self.__data.footerLabel.hide()
for axisId in self.validAxes:
if self.axisEnabled(axisId):
self.axisWidget(axisId).setGeometry(scaleRect[axisId])
if axisId in (self.xBottom, self.xTop):
r = QRegion(scaleRect[axisId])
if self.axisEnabled(self.yLeft):
r = r.subtracted(QRegion(scaleRect[self.yLeft]))
if self.axisEnabled(self.yRight):
r = r.subtracted(QRegion(scaleRect[self.yRight]))
r.translate(-scaleRect[axisId].x(), -scaleRect[axisId].y())
self.axisWidget(axisId).setMask(r)
if not self.axisWidget(axisId).isVisibleTo(self):
self.axisWidget(axisId).show()
else:
self.axisWidget(axisId).hide()
if self.__data.legend:
if self.__data.legend.isEmpty():
self.__data.legend.hide()
else:
self.__data.legend.setGeometry(legendRect)
self.__data.legend.show()
self.__data.canvas.setGeometry(canvasRect)
def getCanvasMarginsHint(self, maps, canvasRect):
"""
Calculate the canvas margins
:param list maps: `QwtPlot.axisCnt` maps, mapping between plot and paint device coordinates
:param QRectF canvasRect: Bounding rectangle where to paint
Plot items might indicate, that they need some extra space
at the borders of the canvas by the `QwtPlotItem.Margins` flag.
.. seealso::
:py:meth:`updateCanvasMargins()`, :py:meth:`getCanvasMarginHint()`
"""
left = top = right = bottom = -1.
for item in self.itemList():
if item.testItemAttribute(QwtPlotItem.Margins):
m = item.getCanvasMarginHint(maps[item.xAxis()],
maps[item.yAxis()], canvasRect)
left = max([left, m[self.yLeft]])
top = max([top, m[self.xTop]])
right = max([right, m[self.yRight]])
bottom = max([bottom, m[self.xBottom]])
return left, top, right, bottom
def updateCanvasMargins(self):
"""
Update the canvas margins
Plot items might indicate, that they need some extra space
at the borders of the canvas by the `QwtPlotItem.Margins` flag.
.. seealso::
:py:meth:`getCanvasMarginsHint()`,
:py:meth:`QwtPlotItem.getCanvasMarginHint()`
"""
maps = [self.canvasMap(axisId) for axisId in self.validAxes]
margins = self.getCanvasMarginsHint(maps, self.canvas().contentsRect())
doUpdate = False
for axisId in self.validAxes:
if margins[axisId] >= 0.:
m = np.ceil(margins[axisId])
self.plotLayout().setCanvasMargin(m, axisId)
doUpdate = True
if doUpdate:
self.updateLayout()
def drawCanvas(self, painter):
"""
Redraw the canvas.
:param QPainter painter: Painter used for drawing
.. warning::
drawCanvas calls drawItems what is also used
for printing. Applications that like to add individual
plot items better overload drawItems()
.. seealso::
:py:meth:`getCanvasMarginsHint()`,
:py:meth:`QwtPlotItem.getCanvasMarginHint()`
"""
maps = [self.canvasMap(axisId) for axisId in self.validAxes]
self.drawItems(painter, self.__data.canvas.contentsRect(), maps)
def drawItems(self, painter, canvasRect, maps):
"""
Redraw the canvas.
:param QPainter painter: Painter used for drawing
:param QRectF canvasRect: Bounding rectangle where to paint
:param list maps: `QwtPlot.axisCnt` maps, mapping between plot and paint device coordinates
.. note::
Usually canvasRect is `contentsRect()` of the plot canvas.
Due to a bug in Qt this rectangle might be wrong for certain
frame styles ( f.e `QFrame.Box` ) and it might be necessary to
fix the margins manually using `QWidget.setContentsMargins()`
"""
for item in self.itemList():
if item and item.isVisible():
painter.save()
painter.setRenderHint(QPainter.Antialiasing,
item.testRenderHint(QwtPlotItem.RenderAntialiased))
painter.setRenderHint(QPainter.HighQualityAntialiasing,
item.testRenderHint(QwtPlotItem.RenderAntialiased))
item.draw(painter, maps[item.xAxis()], maps[item.yAxis()],
canvasRect)
painter.restore()
def canvasMap(self, axisId):
"""
:param int axisId: Axis
:return: Map for the axis on the canvas. With this map pixel coordinates can translated to plot coordinates and vice versa.
.. seealso::
:py:class:`qwt.scale_map.QwtScaleMap`,
:py:meth:`transform()`, :py:meth:`invTransform()`
"""
map_ = QwtScaleMap()
if not self.__data.canvas:
return map_
map_.setTransformation(self.axisScaleEngine(axisId).transformation())
sd = self.axisScaleDiv(axisId)
map_.setScaleInterval(sd.lowerBound(), sd.upperBound())
if self.axisEnabled(axisId):
s = self.axisWidget(axisId)
if axisId in (self.yLeft, self.yRight):
y = s.y() + s.startBorderDist() - self.__data.canvas.y()
h = s.height() - s.startBorderDist() - s.endBorderDist()
map_.setPaintInterval(y+h, y)
else:
x = s.x() + s.startBorderDist() - self.__data.canvas.x()
w = s.width() - s.startBorderDist() - s.endBorderDist()
map_.setPaintInterval(x, x+w)
else:
canvasRect = self.__data.canvas.contentsRect()
if axisId in (self.yLeft, self.yRight):
top = 0
if not self.plotLayout().alignCanvasToScale(self.xTop):
top = self.plotLayout().canvasMargin(self.xTop)
bottom = 0
if not self.plotLayout().alignCanvasToScale(self.xBottom):
bottom = self.plotLayout().canvasMargin(self.xBottom)
map_.setPaintInterval(canvasRect.bottom()-bottom,
canvasRect.top()+top)
else:
left = 0
if not self.plotLayout().alignCanvasToScale(self.yLeft):
left = self.plotLayout().canvasMargin(self.yLeft)
right = 0
if not self.plotLayout().alignCanvasToScale(self.yRight):
right = self.plotLayout().canvasMargin(self.yRight)
map_.setPaintInterval(canvasRect.left()+left,
canvasRect.right()-right)
return map_
def setCanvasBackground(self, brush):
"""
Change the background of the plotting area
Sets brush to `QPalette.Window` of all color groups of
the palette of the canvas. Using `canvas().setPalette()`
is a more powerful way to set these colors.
:param QBrush brush: New background brush
.. seealso::
:py:meth:`canvasBackground()`
"""
pal = self.__data.canvas.palette()
pal.setBrush(QPalette.Window, brush)
self.canvas().setPalette(pal)
def canvasBackground(self):
"""
:return: Background brush of the plotting area.
.. seealso::
:py:meth:`setCanvasBackground()`
"""
return self.canvas().palette().brush(QPalette.Normal, QPalette.Window)
def axisValid(self, axisId):
"""
:param int axisId: Axis
:return: True if the specified axis exists, otherwise False
"""
return axisId in QwtPlot.validAxes
def insertLegend(self, legend, pos=None, ratio=-1):
"""
Insert a legend
If the position legend is `QwtPlot.LeftLegend` or `QwtPlot.RightLegend`
the legend will be organized in one column from top to down.
Otherwise the legend items will be placed in a table
with a best fit number of columns from left to right.
insertLegend() will set the plot widget as parent for the legend.
The legend will be deleted in the destructor of the plot or when
another legend is inserted.
Legends, that are not inserted into the layout of the plot widget
need to connect to the legendDataChanged() signal. Calling updateLegend()
initiates this signal for an initial update. When the application code
wants to implement its own layout this also needs to be done for
rendering plots to a document ( see QwtPlotRenderer ).
:param qwt.legend.QwtAbstractLegend legend: Legend
:param QwtPlot.LegendPosition pos: The legend's position.
:param float ratio: Ratio between legend and the bounding rectangle of title, canvas and axes
.. note::
For top/left position the number of columns will be limited to 1,
otherwise it will be set to unlimited.
.. note::
The legend will be shrunk if it would need more space than the
given ratio. The ratio is limited to ]0.0 .. 1.0].
In case of <= 0.0 it will be reset to the default ratio.
The default vertical/horizontal ratio is 0.33/0.5.
.. seealso::
:py:meth:`legend()`,
:py:meth:`qwt.plot_layout.QwtPlotLayout.legendPosition()`,
:py:meth:`qwt.plot_layout.QwtPlotLayout.setLegendPosition()`
"""
if pos is None:
pos = self.RightLegend
self.__data.layout.setLegendPosition(pos, ratio)
if legend != self.__data.legend:
if self.__data.legend and self.__data.legend.parent() is self:
del self.__data.legend
self.__data.legend = legend
if self.__data.legend:
self.legendDataChanged.connect(self.__data.legend.updateLegend)
if self.__data.legend.parent() is not self:
self.__data.legend.setParent(self)
qwtEnableLegendItems(self, False)
self.updateLegend()
qwtEnableLegendItems(self, True)
lpos = self.__data.layout.legendPosition()
if legend is not None:
if lpos in (self.LeftLegend, self.RightLegend):
if legend.maxColumns() == 0:
legend.setMaxColumns(1)
elif lpos in (self.TopLegend, self.BottomLegend):
legend.setMaxColumns(0)
previousInChain = None
if lpos == self.LeftLegend:
previousInChain = self.axisWidget(QwtPlot.xTop)
elif lpos == self.TopLegend:
previousInChain = self
elif lpos == self.RightLegend:
previousInChain = self.axisWidget(QwtPlot.yRight)
elif lpos == self.BottomLegend:
previousInChain = self.footerLabel()
if previousInChain:
qwtSetTabOrder(previousInChain, legend, True)
self.updateLayout()
def updateLegend(self, plotItem=None):
"""
If plotItem is None, emit QwtPlot.legendDataChanged for all
plot item. Otherwise, emit the signal for passed plot item.
:param qwt.plot.QwtPlotItem plotItem: Plot item
.. seealso::
:py:meth:`QwtPlotItem.legendData()`, :py:data:`QwtPlot.legendDataChanged`
"""
if plotItem is None:
items = list(self.itemList())
else:
items = [plotItem]
for plotItem in items:
if plotItem is None:
continue
legendData = []
if plotItem.testItemAttribute(QwtPlotItem.Legend):
legendData = plotItem.legendData()
self.legendDataChanged.emit(plotItem, legendData)
def updateLegendItems(self, plotItem, legendData):
"""
Update all plot items interested in legend attributes
Call `QwtPlotItem.updateLegend()`, when the
`QwtPlotItem.LegendInterest` flag is set.
:param qwt.plot.QwtPlotItem plotItem: Plot item
:param list legendData: Entries to be displayed for the plot item ( usually 1 )
.. seealso::
:py:meth:`QwtPlotItem.LegendInterest()`,
:py:meth:`QwtPlotItem.updateLegend`
"""
if plotItem is not None:
for item in self.itemList():
if item.testItemInterest(QwtPlotItem.LegendInterest):
item.updateLegend(plotItem, legendData)
def attachItem(self, plotItem, on):
"""
Attach/Detach a plot item
:param qwt.plot.QwtPlotItem plotItem: Plot item
:param bool on: When true attach the item, otherwise detach it
"""
if plotItem.testItemInterest(QwtPlotItem.LegendInterest):
for item in self.itemList():
legendData = []
if on and item.testItemAttribute(QwtPlotItem.Legend):
legendData = item.legendData()
plotItem.updateLegend(item, legendData)
if on:
self.insertItem(plotItem)
else:
self.removeItem(plotItem)
self.itemAttached.emit(plotItem, on)
if plotItem.testItemAttribute(QwtPlotItem.Legend):
if on:
self.updateLegend(plotItem)
else:
self.legendDataChanged.emit(plotItem, [])
self.autoRefresh()
def print_(self, printer):
"""
Print plot to printer
:param printer: Printer
:type printer: QPaintDevice or QPrinter or QSvgGenerator
"""
from qwt.plot_renderer import QwtPlotRenderer
renderer = QwtPlotRenderer(self)
renderer.renderTo(self, printer)
def exportTo(self, filename, size=(800, 600), size_mm=None,
resolution=72., format_=None):
"""
Export plot to PDF or image file (SVG, PNG, ...)
:param str filename: Filename
:param tuple size: (width, height) size in pixels
:param tuple size_mm: (width, height) size in millimeters
:param float resolution: Image resolution
:param str format_: File format (PDF, SVG, PNG, ...)
"""
if size_mm is None:
size_mm = tuple(25.4*np.array(size)/resolution)
from qwt.plot_renderer import QwtPlotRenderer
renderer = QwtPlotRenderer(self)
renderer.renderDocument(self, filename, size_mm, resolution, format_)
class QwtPlotItem_PrivateData(object):
def __init__(self):
self.plot = None
self.isVisible = True
self.attributes = 0
self.interests = 0
self.renderHints = 0
self.z = 0.
self.xAxis = QwtPlot.xBottom
self.yAxis = QwtPlot.yLeft
self.legendIconSize = QSize(8, 8)
self.title = None # QwtText
class QwtPlotItem(object):
"""
Base class for items on the plot canvas
A plot item is "something", that can be painted on the plot canvas,
or only affects the scales of the plot widget. They can be categorized as:
- Representator
A "Representator" is an item that represents some sort of data
on the plot canvas. The different representator classes are organized
according to the characteristics of the data:
- :py:class:`qwt.plot_marker.QwtPlotMarker`: Represents a point or a
horizontal/vertical coordinate
- :py:class:`qwt.plot_curve.QwtPlotCurve`: Represents a series of
points
- Decorators
A "Decorator" is an item, that displays additional information, that
is not related to any data:
- :py:class:`qwt.plot_grid.QwtPlotGrid`
Depending on the `QwtPlotItem.ItemAttribute` flags, an item is included
into autoscaling or has an entry on the legend.
Before misusing the existing item classes it might be better to
implement a new type of plot item
( don't implement a watermark as spectrogram ).
Deriving a new type of `QwtPlotItem` primarily means to implement
the `YourPlotItem.draw()` method.
.. seealso::
The cpuplot example shows the implementation of additional plot items.
.. py:class:: QwtPlotItem([title=None])
Constructor
:param title: Title of the item
:type title: qwt.text.QwtText or str
"""
# enum RttiValues
(Rtti_PlotItem, Rtti_PlotGrid, Rtti_PlotScale, Rtti_PlotLegend,
Rtti_PlotMarker, Rtti_PlotCurve, Rtti_PlotSpectroCurve,
Rtti_PlotIntervalCurve, Rtti_PlotHistogram, Rtti_PlotSpectrogram,
Rtti_PlotSVG, Rtti_PlotTradingCurve, Rtti_PlotBarChart,
Rtti_PlotMultiBarChart, Rtti_PlotShape, Rtti_PlotTextLabel,
Rtti_PlotZone) = list(range(17))
Rtti_PlotUserItem = 1000
# enum ItemAttribute
Legend = 0x01
AutoScale = 0x02
Margins = 0x04
# enum ItemInterest
ScaleInterest = 0x01
LegendInterest = 0x02
# enum RenderHint
RenderAntialiased = 0x1
def __init__(self, title=None):
"""title: QwtText"""
if title is None:
title = QwtText("")
if hasattr(title, 'capitalize'): # avoids dealing with Py3K compat.
title = QwtText(title)
assert isinstance(title, QwtText)
self.__data = QwtPlotItem_PrivateData()
self.__data.title = title
def attach(self, plot):
"""
Attach the item to a plot.
This method will attach a `QwtPlotItem` to the `QwtPlot` argument.
It will first detach the `QwtPlotItem` from any plot from a previous
call to attach (if necessary). If a None argument is passed, it will
detach from any `QwtPlot` it was attached to.
:param qwt.plot.QwtPlot plot: Plot widget
.. seealso::
:py:meth:`detach()`
"""
if plot is self.__data.plot:
return
if self.__data.plot:
self.__data.plot.attachItem(self, False)
self.__data.plot = plot
if self.__data.plot:
self.__data.plot.attachItem(self, True)
def detach(self):
"""
Detach the item from a plot.
This method detaches a `QwtPlotItem` from any `QwtPlot` it has been
associated with.
.. seealso::
:py:meth:`attach()`
"""
self.attach(None)
def rtti(self):
"""
Return rtti for the specific class represented. `QwtPlotItem` is
simply a virtual interface class, and base classes will implement
this method with specific rtti values so a user can differentiate
them.
:return: rtti value
"""
return self.Rtti_PlotItem
def plot(self):
"""
:return: attached plot
"""
return self.__data.plot
def z(self):
"""
Plot items are painted in increasing z-order.
:return: item z order
.. seealso::
:py:meth:`setZ()`, :py:meth:`QwtPlotDict.itemList()`
"""
return self.__data.z
def setZ(self, z):
"""
Set the z value
Plot items are painted in increasing z-order.
:param float z: Z-value
.. seealso::
:py:meth:`z()`, :py:meth:`QwtPlotDict.itemList()`
"""
if self.__data.z != z:
if self.__data.plot:
self.__data.plot.attachItem(self, False)
self.__data.z = z
if self.__data.plot:
self.__data.plot.attachItem(self, True)
self.itemChanged()
def setTitle(self, title):
"""
Set a new title
:param title: Title
:type title: qwt.text.QwtText or str
.. seealso::
:py:meth:`title()`
"""
if not isinstance(title, QwtText):
title = QwtText(title)
if self.__data.title != title:
self.__data.title = title
self.legendChanged()
def title(self):
"""
:return: Title of the item
.. seealso::
:py:meth:`setTitle()`
"""
return self.__data.title
def setItemAttribute(self, attribute, on=True):
"""
Toggle an item attribute
:param int attribute: Attribute type
:param bool on: True/False
.. seealso::
:py:meth:`testItemAttribute()`
"""
if bool(self.__data.attributes & attribute) != on:
if on:
self.__data.attributes |= attribute
else:
self.__data.attributes &= ~attribute
if attribute == QwtPlotItem.Legend:
self.legendChanged()
self.itemChanged()
def testItemAttribute(self, attribute):
"""
Test an item attribute
:param int attribute: Attribute type
:return: True/False
.. seealso::
:py:meth:`setItemAttribute()`
"""
return bool(self.__data.attributes & attribute)
def setItemInterest(self, interest, on=True):
"""
Toggle an item interest
:param int attribute: Interest type
:param bool on: True/False
.. seealso::
:py:meth:`testItemInterest()`
"""
if bool(self.__data.interests & interest) != on:
if on:
self.__data.interests |= interest
else:
self.__data.interests &= ~interest
self.itemChanged()
def testItemInterest(self, interest):
"""
Test an item interest
:param int attribute: Interest type
:return: True/False
.. seealso::
:py:meth:`setItemInterest()`
"""
return bool(self.__data.interests & interest)
def setRenderHint(self, hint, on=True):
"""
Toggle a render hint
:param int hint: Render hint
:param bool on: True/False
.. seealso::
:py:meth:`testRenderHint()`
"""
if bool(self.__data.renderHints & hint) != on:
if on:
self.__data.renderHints |= hint
else:
self.__data.renderHints &= ~hint
self.itemChanged()
def testRenderHint(self, hint):
"""
Test a render hint
:param int attribute: Render hint
:return: True/False
.. seealso::
:py:meth:`setRenderHint()`
"""
return bool(self.__data.renderHints & hint)
def setLegendIconSize(self, size):
"""
Set the size of the legend icon
The default setting is 8x8 pixels
:param QSize size: Size
.. seealso::
:py:meth:`legendIconSize()`, :py:meth:`legendIcon()`
"""
if self.__data.legendIconSize != size:
self.__data.legendIconSize = size
self.legendChanged()
def legendIconSize(self):
"""
:return: Legend icon size
.. seealso::
:py:meth:`setLegendIconSize()`, :py:meth:`legendIcon()`
"""
return self.__data.legendIconSize
def legendIcon(self, index, size):
"""
:param int index: Index of the legend entry (usually there is only one)
:param QSizeF size: Icon size
:return: Icon representing the item on the legend
The default implementation returns an invalid icon
.. seealso::
:py:meth:`setLegendIconSize()`, :py:meth:`legendData()`
"""
return QwtGraphic()
def defaultIcon(self, brush, size):
"""
Return a default icon from a brush
The default icon is a filled rectangle used
in several derived classes as legendIcon().
:param QBrush brush: Fill brush
:param QSizeF size: Icon size
:return: A filled rectangle
"""
icon = QwtGraphic()
if not size.isEmpty():
icon.setDefaultSize(size)
r = QRectF(0, 0, size.width(), size.height())
painter = QPainter(icon)
painter.fillRect(r, brush)
return icon
def show(self):
"""Show the item"""
self.setVisible(True)
def hide(self):
"""Hide the item"""
self.setVisible(False)
def setVisible(self, on):
"""
Show/Hide the item
:param bool on: Show if True, otherwise hide
.. seealso::
:py:meth:`isVisible()`, :py:meth:`show()`, :py:meth:`hide()`
"""
if on != self.__data.isVisible:
self.__data.isVisible = on
self.itemChanged()
def isVisible(self):
"""
:return: True if visible
.. seealso::
:py:meth:`setVisible()`, :py:meth:`show()`, :py:meth:`hide()`
"""
return self.__data.isVisible
def itemChanged(self):
"""
Update the legend and call `QwtPlot.autoRefresh()` for the
parent plot.
.. seealso::
:py:meth:`QwtPlot.legendChanged()`, :py:meth:`QwtPlot.autoRefresh()`
"""
if self.__data.plot:
self.__data.plot.autoRefresh()
def legendChanged(self):
"""
Update the legend of the parent plot.
.. seealso::
:py:meth:`QwtPlot.updateLegend()`, :py:meth:`itemChanged()`
"""
if self.testItemAttribute(QwtPlotItem.Legend) and self.__data.plot:
self.__data.plot.updateLegend(self)
def setAxes(self, xAxis, yAxis):
"""
Set X and Y axis
The item will painted according to the coordinates of its Axes.
:param int xAxis: X Axis (`QwtPlot.xBottom` or `QwtPlot.xTop`)
:param int yAxis: Y Axis (`QwtPlot.yLeft` or `QwtPlot.yRight`)
.. seealso::
:py:meth:`setXAxis()`, :py:meth:`setYAxis()`,
:py:meth:`xAxis()`, :py:meth:`yAxis()`
"""
if xAxis == QwtPlot.xBottom or xAxis == QwtPlot.xTop:
self.__data.xAxis = xAxis
if yAxis == QwtPlot.yLeft or yAxis == QwtPlot.yRight:
self.__data.yAxis = yAxis
self.itemChanged()
def setAxis(self, xAxis, yAxis):
"""
Set X and Y axis
.. warning::
`setAxis` has been removed in Qwt6: please use
:py:meth:`setAxes()` instead
"""
import warnings
warnings.warn("`setAxis` has been removed in Qwt6: "\
"please use `setAxes` instead", RuntimeWarning)
self.setAxes(xAxis, yAxis)
def setXAxis(self, axis):
"""
Set the X axis
The item will painted according to the coordinates its Axes.
:param int axis: X Axis (`QwtPlot.xBottom` or `QwtPlot.xTop`)
.. seealso::
:py:meth:`setAxes()`, :py:meth:`setYAxis()`,
:py:meth:`xAxis()`, :py:meth:`yAxis()`
"""
if axis in (QwtPlot.xBottom, QwtPlot.xTop):
self.__data.xAxis = axis
self.itemChanged()
def setYAxis(self, axis):
"""
Set the Y axis
The item will painted according to the coordinates its Axes.
:param int axis: Y Axis (`QwtPlot.yLeft` or `QwtPlot.yRight`)
.. seealso::
:py:meth:`setAxes()`, :py:meth:`setXAxis()`,
:py:meth:`xAxis()`, :py:meth:`yAxis()`
"""
if axis in (QwtPlot.yLeft, QwtPlot.yRight):
self.__data.yAxis = axis
self.itemChanged()
def xAxis(self):
"""
:return: xAxis
"""
return self.__data.xAxis
def yAxis(self):
"""
:return: yAxis
"""
return self.__data.yAxis
def boundingRect(self):
"""
:return: An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0)
.. note::
A width or height < 0.0 is ignored by the autoscaler
"""
return QRectF(1.0, 1.0, -2.0, -2.0)
def getCanvasMarginHint(self, xMap, yMap, canvasRect):
"""
Calculate a hint for the canvas margin
When the QwtPlotItem::Margins flag is enabled the plot item
indicates, that it needs some margins at the borders of the canvas.
This is f.e. used by bar charts to reserve space for displaying
the bars.
The margins are in target device coordinates ( pixels on screen )
:param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
:param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
:param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
.. seealso::
:py:meth:`QwtPlot.getCanvasMarginsHint()`,
:py:meth:`QwtPlot.updateCanvasMargins()`,
"""
left = top = right = bottom = 0.
return left, top, right, bottom
def legendData(self):
"""
Return all information, that is needed to represent
the item on the legend
`QwtLegendData` is basically a list of QVariants that makes it
possible to overload and reimplement legendData() to
return almost any type of information, that is understood
by the receiver that acts as the legend.
The default implementation returns one entry with
the title() of the item and the legendIcon().
:return: Data, that is needed to represent the item on the legend
.. seealso::
:py:meth:`title()`, :py:meth:`legendIcon()`,
:py:class:`qwt.legend.QwtLegend`
"""
data = QwtLegendData()
label = self.title()
label.setRenderFlags(label.renderFlags() & Qt.AlignLeft)
data.setValue(QwtLegendData.TitleRole, label)
graphic = self.legendIcon(0, self.legendIconSize())
if not graphic.isNull():
data.setValue(QwtLegendData.IconRole, graphic)
return [data]
def updateLegend(self, item, data):
"""
Update the item to changes of the legend info
Plot items that want to display a legend ( not those, that want to
be displayed on a legend ! ) will have to implement updateLegend().
updateLegend() is only called when the LegendInterest interest
is enabled. The default implementation does nothing.
:param qwt.plot.QwtPlotItem item: Plot item to be displayed on a legend
:param list data: Attributes how to display item on the legend
.. note::
Plot items, that want to be displayed on a legend
need to enable the `QwtPlotItem.Legend` flag and to implement
legendData() and legendIcon()
"""
pass
def scaleRect(self, xMap, yMap):
"""
Calculate the bounding scale rectangle of 2 maps
:param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
:param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
:return: Bounding scale rect of the scale maps, not normalized
"""
return QRectF(xMap.s1(), yMap.s1(), xMap.sDist(), yMap.sDist())
def paintRect(self, xMap, yMap):
"""
Calculate the bounding paint rectangle of 2 maps
:param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
:param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
:return: Bounding paint rectangle of the scale maps, not normalized
"""
return QRectF(xMap.p1(), yMap.p1(), xMap.pDist(), yMap.pDist())
|