Advertisement
Guest User

gg

a guest
Jul 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtGui import *
  3. from PyQt5.QtWidgets import *
  4. from PyQt5.QtChart import *
  5.  
  6. if __name__ == '__main__':
  7.     import sys
  8.  
  9.     a = QApplication(sys.argv)
  10.    
  11.     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']
  12.     y = [1, 6, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3]
  13.  
  14.     #Chart Type
  15.     series = QLineSeries()
  16.     for t, val in zip(x2, y):
  17.         series.append(QDateTime.fromString(t, "yyyy-MM-dd hh:mm:ss").toMSecsSinceEpoch(), val)
  18.  
  19.     # Create Chart and set General Chart setting
  20.     chart = QChart()
  21.     chart.addSeries(series)
  22.     chart.setTitle("Temperature records in celcius")
  23.     #chart.setAnimationOptions(QChart.SeriesAnimations)
  24.  
  25.     # X Axis Settings  
  26.     axisX = QDateTimeAxis()
  27.     axisX.setTickCount(20)
  28.     axisX.setFormat("dd HH:mm") #https://doc.qt.io/qt-5/qdatetime.html#toString-2
  29.     axisX.setTitleText("Day")
  30.     chart.addAxis(axisX, Qt.AlignBottom)
  31.     series.attachAxis(axisX)
  32.  
  33.     # Y Axis Settings
  34.     axisY = QValueAxis()
  35.     axisY.setLabelFormat("%i")
  36.     axisY.setTickCount(10)
  37.     axisY.setTitleText("Temperature C")
  38.     chart.addAxis(axisY, Qt.AlignLeft)
  39.     series.attachAxis(axisY)
  40.  
  41.     # 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.
  42.     chartView = QChartView(chart)
  43.     chartView.setRenderHint(QPainter.Antialiasing)
  44.  
  45.     chart.axisY(series).setRange(min(y)-1, max(y)+1)
  46.     chart.legend().setVisible(True)
  47.     chart.legend().setAlignment(Qt.AlignBottom)
  48.     window = QMainWindow()
  49.     window.setCentralWidget(chartView)
  50.     window.resize(1280, 480)  
  51.     window.show()
  52.     sys.exit(a.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement