Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- from PyQt5.QtChart import *
- if __name__ == '__main__':
- import sys
- a = QApplication(sys.argv)
- x2 = ['2018-07-01 13:06:38', '2018-07-01 13:16:38','2018-07-01 13:26:38','2018-07-01 13:36:38','2018-07-01 13:46:38','2018-07-01 13:56:38','2018-07-01 14:06:38','2018-07-01 14:16:38','2018-07-01 14:26:38','2018-07-01 14:36:38','2018-07-01 14:46:38','2018-07-01 14:56:38','2018-07-01 15:06:38']
- y = [1, 6, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3]
- #Chart Type
- series = QLineSeries()
- for t, val in zip(x2, y):
- series.append(QDateTime.fromString(t, "yyyy-MM-dd hh:mm:ss").toMSecsSinceEpoch(), val)
- # Create Chart and set General Chart setting
- chart = QChart()
- chart.addSeries(series)
- chart.setTitle("Temperature records in celcius")
- #chart.setAnimationOptions(QChart.SeriesAnimations)
- # X Axis Settings
- axisX = QDateTimeAxis()
- axisX.setTickCount(20)
- axisX.setFormat("dd HH:mm") #https://doc.qt.io/qt-5/qdatetime.html#toString-2
- axisX.setTitleText("Day")
- chart.addAxis(axisX, Qt.AlignBottom)
- series.attachAxis(axisX)
- # Y Axis Settings
- axisY = QValueAxis()
- axisY.setLabelFormat("%i")
- axisY.setTickCount(10)
- axisY.setTitleText("Temperature C")
- chart.addAxis(axisY, Qt.AlignLeft)
- series.attachAxis(axisY)
- # Create a QChartView object with QChart as a parameter. This way we don't need to create the QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
- chartView = QChartView(chart)
- chartView.setRenderHint(QPainter.Antialiasing)
- chart.axisY(series).setRange(min(y)-1, max(y)+1)
- chart.legend().setVisible(True)
- chart.legend().setAlignment(Qt.AlignBottom)
- window = QMainWindow()
- window.setCentralWidget(chartView)
- window.resize(1280, 480)
- window.show()
- sys.exit(a.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement