Results 1 to 4 of 4

Thread: How not to display all x axis coordinate labels pyqt5

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2019
    Posts
    12
    Thanks
    5
    Qt products
    Platforms
    Windows

    Default

    How not to display all x axis coordinate labels pyqt5?
    For example every 30 values.

    It would also be good to find out how instead of indexes 1, 2, 3 ......195, 196 display datetime data, but without days off.

    Data " file.txt" are located here https://drive.google.com/file/d/1nzf...ew?usp=sharing

    Qt Code:
    1. from PyQt5 import QtCore, QtGui, QtWidgets, QtChart
    2. from PyQt5.QtCore import Qt
    3. import math
    4. import numpy as np
    5. import pandas as pd
    6.  
    7. df = pd.read_csv('file.txt',
    8. index_col='DATE',
    9. parse_dates=True,
    10. infer_datetime_format=True)
    11.  
    12.  
    13. date = df.iloc[:, 0].index.date
    14. o = df.iloc[:, 0].values
    15. h = df.iloc[:, 1].values
    16. l = df.iloc[:, 2].values
    17. z = df.iloc[:, 3].values
    18. x = len(z)
    19. x_ = x - 1
    20.  
    21. class MainWindow(QtWidgets.QMainWindow):
    22. def __init__(self, parent=None):
    23. super().__init__(parent)
    24.  
    25. self.step = 30
    26. self._chart_view = QtChart.QChartView()
    27. self.scrollbar = QtWidgets.QScrollBar(
    28. QtCore.Qt.Horizontal,
    29. sliderMoved=self.onAxisSliderMoved,
    30. pageStep=self.step,
    31. )
    32.  
    33.  
    34. self.scrollbar.setRange(0, x_)
    35.  
    36. central_widget = QtWidgets.QWidget()
    37. self.setCentralWidget(central_widget)
    38.  
    39. lay = QtWidgets.QVBoxLayout(central_widget)
    40. for w in (self._chart_view, self.scrollbar):
    41. lay.addWidget(w)
    42.  
    43. self._chart = QtChart.QChart()
    44. self._candlestick_serie = QtChart.QCandlestickSeries()
    45.  
    46. tm = []
    47.  
    48. for i in range(0, len(z)):
    49. o_ = o[i]
    50. h_ = h[i]
    51. l_ = l[i]
    52. c_ = z[i]
    53. self._candlestick_serie.append(QtChart.QCandlestickSet(o_, h_, l_, c_))
    54. tm.append(str(i))
    55.  
    56. min_x, max_x = 0, x_
    57.  
    58. self._chart.addSeries(self._candlestick_serie)
    59. self._chart.createDefaultAxes()
    60. self._chart.legend().hide()
    61. self._chart.axisX(self._candlestick_serie).setCategories(tm)
    62. self._chart_view.setChart(self._chart)
    63. self.lims = np.array([min_x, max_x])
    64. self.onAxisSliderMoved(self.scrollbar.value())
    65. self.adjust_axes(1, 31)
    66.  
    67.  
    68. def adjust_axes(self, value_min, value_max):
    69. if value_min > 0 and value_max > 0 and value_max <= x_ and value_max > value_min:
    70. self._chart.axisX(self._candlestick_serie).setRange(str(value_min), str(value_max))
    71.  
    72. @QtCore.pyqtSlot(int)
    73. def onAxisSliderMoved(self, value):
    74. value2 = value + self.step
    75. value1 = value
    76. if value2 >= x_:
    77. value2 = x_
    78. value1 = value2 - self.step
    79. self.adjust_axes(math.floor(value1), math.ceil(value2))
    80.  
    81.  
    82.  
    83. if __name__ == "__main__":
    84. import sys
    85.  
    86. app = QtWidgets.QApplication(sys.argv)
    87. w = MainWindow()
    88. w.show()
    89. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    123.jpg
    Last edited by quant; 6th June 2020 at 18:19.

Similar Threads

  1. PyQt5 - Reading values from a custom QTablewidget cell
    By sheejo in forum Qt Programming
    Replies: 2
    Last Post: 17th May 2020, 17:04
  2. Replies: 2
    Last Post: 28th July 2019, 22:11
  3. QwtPlot - showing two values on x-Axis
    By Earinor in forum Qwt
    Replies: 3
    Last Post: 30th March 2017, 10:47
  4. Cannot get the axis's current min and max values
    By Alexander111122 in forum Qwt
    Replies: 2
    Last Post: 24th February 2016, 16:18
  5. Y-Axis values draw artifact
    By alex-krutikov in forum Qwt
    Replies: 3
    Last Post: 23rd October 2009, 09:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.