Results 1 to 5 of 5

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

  1. #1
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    7
    Qt products
    Platforms
    Windows

    Default Number of tick marks on the axis in QBarCategoryAxis.

    I managed to put string values on the x axis(datetime data is converted to a string).
    Created on the x axis QBarCategoryAxis.
    Everything would be fine, but I can't adjust tick marks on the axis.

    To avoid being verbose more details here https://forum.qt.io/topic/118786/can...settickcount/2

    If that's not possible, say so.
    Since this idea is long-standing and time-consuming.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    Looking at the docs for QBarCategoryAxis the intended use of this Axis is for discrete categories on a bar chart, not an abbreviation of a continuous time line. Bar chart categories are typically few in number. This class renders as many tick marks as needed to separate the categories.

    The QDateTimeAxis class is for displaying a continuous time line, which includes the two days of weekend (I assume) that result in gaps because you do not have data on those days.
    You might be able to use QDateTimeAxis considering the answer in this Stack Overflow response: https://stackoverflow.com/questions/...goryaxis-in-qt.
    Ultimately, I think you would end up writing your own QuantWeekdayTimeAxis subclass of QAbstractAxisClass to achieve what you want.

    As a completely different approach look at Qwt, particularly the QwtPlotTradingCurve (also https://qwt.sourceforge.io/otherscreenshots.html). The learning curve here is steeper, but the flexibility is almost certainly there.

  3. The following user says thank you to ChrisW67 for this useful post:

    quant (20th September 2020)

  4. #3
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    7
    Qt products
    Platforms
    Windows

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

    Thank you, I did all this earlier.
    Maybe you can still change the labels for the axes?

  5. #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 16:59.

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    Why don't you check out QCustomPlot? It is much better than the brain-dead QChart library, and you can do virtually anything with it through customization. Things like this.

    Edit - Sorry, looks like there may not be Python bindings.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 4th September 2012, 20:28
  2. Replies: 1
    Last Post: 5th March 2012, 07:34
  3. qslider fixed to tick marks
    By holst in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2009, 13:18
  4. QSlider with tick marks numbers
    By mastupristi in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2009, 09: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, 17: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.