Results 1 to 5 of 5

Thread: Number of tick marks on the axis in QBarCategoryAxis.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    7
    Qt products
    Platforms
    Windows

    Default Re: Number of tick marks on the axis in QBarCategoryAxis.

    I still haven't been able to solve the problem. If I use the QDateTimeAxis axis for the candlestick chart, then when there is no data, empty gaps are obtained in the chart. I did as advised and created a line chart with the QDateTimeAxis axis, and for the candlestick chart I used the QValueAxis axis. But, it's still far from what need. On the chart, candlestick and line (int_line_serie) charts have a QValueAxis axis, another line chart (dt_line_serie) has a QDateTimeAxis axis. It can be seen that the first two match, but the linear (green line) QDateTimeAxis does not. I searched a lot how to create a QuantWeekdayTimeAxis subclass of QAbstractAxisClass but didn't find anything. Can someone tell me how to do this in pyqt or at least in C ++.

    Need an axis so that I can adjust the number of divisions. In matplotlib, you can use the date time in string format, so this problem was solved.

    a.jpg

    Qt Code:
    1. from PyQt5 import QtWidgets, QtChart
    2. from PyQt5.QtGui import QPen
    3. from PyQt5.QtCore import *
    4. from PyQt5.QtChart import *
    5. import pandas_datareader.data as web
    6.  
    7. df = web.DataReader('GE', 'yahoo', start='2022-05-01', end='2022-05-25')
    8.  
    9. date = df.index
    10. x = len(date)
    11.  
    12. qt = [None] * x
    13.  
    14. for i in range(0, x):
    15. qt[i] = QDateTime(date[i]).toMSecsSinceEpoch()
    16.  
    17.  
    18. class MainWindow(QtWidgets.QMainWindow):
    19. def __init__(self, parent=None):
    20. super().__init__(parent)
    21.  
    22. self._chart_view = QtChart.QChartView()
    23.  
    24. central_widget = QtWidgets.QWidget()
    25. self.setCentralWidget(central_widget)
    26.  
    27. lay = QtWidgets.QVBoxLayout(central_widget)
    28. lay.addWidget(self._chart_view)
    29.  
    30. self._chart = QtChart.QChart()
    31. self._candlestick_serie = QtChart.QCandlestickSeries()
    32. self.dt_line_serie = QtChart.QLineSeries()
    33. self.int_line_serie = QtChart.QLineSeries()
    34.  
    35. st = QPen(Qt.red)
    36. st.setWidth(3)
    37. self.int_line_serie.setPen(st)
    38.  
    39. for i in range(0, len(df)):
    40. o_ = df.iloc[i, 2]
    41. h_ = df.iloc[i, 0]
    42. l_ = df.iloc[i, 1]
    43. c_ = df.iloc[i, 3]
    44. self._candlestick_serie.append(QtChart.QCandlestickSet(o_, h_, l_, c_, float(i)))
    45. self.dt_line_serie.append(qt[i], o_)
    46. self.int_line_serie.append(float(i), o_)
    47.  
    48. self._chart.addSeries(self._candlestick_serie)
    49. self._chart.addSeries(self.dt_line_serie)
    50. self._chart.addSeries(self.int_line_serie)
    51. self._chart.legend().hide()
    52.  
    53. self._chart_view.setChart(self._chart)
    54.  
    55. axisX = QValueAxis()
    56. axisX.setLabelFormat("%d")
    57. self._chart.addAxis(axisX, Qt.AlignBottom)
    58. self._candlestick_serie.attachAxis(axisX)
    59. self.int_line_serie.attachAxis(axisX)
    60.  
    61. axisX = QDateTimeAxis()
    62. axisX.setFormat("yyyy-MM-dd")
    63. self._chart.addAxis(axisX, Qt.AlignBottom)
    64. self.dt_line_serie.attachAxis(axisX)
    65.  
    66. axisY = QValueAxis()
    67. self._chart.addAxis(axisY, Qt.AlignLeft)
    68. self._candlestick_serie.attachAxis(axisY)
    69. self.dt_line_serie.attachAxis(axisY)
    70. self.int_line_serie.attachAxis(axisY)
    71.  
    72.  
    73. if __name__ == "__main__":
    74. import sys
    75.  
    76. app = QtWidgets.QApplication(sys.argv)
    77. w = MainWindow()
    78. w.show()
    79. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    Last edited by quant; 19th November 2022 at 15:59.

Similar Threads

  1. Replies: 4
    Last Post: 4th September 2012, 19:28
  2. Replies: 1
    Last Post: 5th March 2012, 06:34
  3. qslider fixed to tick marks
    By holst in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2009, 12:18
  4. QSlider with tick marks numbers
    By mastupristi in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2009, 08:32
  5. QSlider with a custom set of labels for the tick marks?
    By whitefurrows in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2007, 16:05

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
  •  
Qt is a trademark of The Qt Company.