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.
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.
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?
1 Attachment(s)
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.
Attachment 13771
Code:
from PyQt5 import QtWidgets, QtChart
from PyQt5.
QtGui import
QPenfrom PyQt5.QtCore import *
from PyQt5.QtChart import *
import pandas_datareader.data as web
df = web.DataReader('GE', 'yahoo', start='2022-05-01', end='2022-05-25')
date = df.index
x = len(date)
qt = [None] * x
for i in range(0, x):
qt
[i
] = QDateTime(date
[i
]).
toMSecsSinceEpoch()
def __init__(self, parent=None):
super().__init__(parent)
self._chart_view = QtChart.QChartView()
central_widget
= QtWidgets.
QWidget() self.setCentralWidget(central_widget)
lay.addWidget(self._chart_view)
self._chart = QtChart.QChart()
self._candlestick_serie = QtChart.QCandlestickSeries()
self.dt_line_serie = QtChart.QLineSeries()
self.int_line_serie = QtChart.QLineSeries()
st.setWidth(3)
self.int_line_serie.setPen(st)
for i in range(0, len(df)):
o_ = df.iloc[i, 2]
h_ = df.iloc[i, 0]
l_ = df.iloc[i, 1]
c_ = df.iloc[i, 3]
self._candlestick_serie.append(QtChart.QCandlestickSet(o_, h_, l_, c_, float(i)))
self.dt_line_serie.append(qt[i], o_)
self.int_line_serie.append(float(i), o_)
self._chart.addSeries(self._candlestick_serie)
self._chart.addSeries(self.dt_line_serie)
self._chart.addSeries(self.int_line_serie)
self._chart.legend().hide()
self._chart_view.setChart(self._chart)
axisX = QValueAxis()
axisX.setLabelFormat("%d")
self._chart.addAxis(axisX, Qt.AlignBottom)
self._candlestick_serie.attachAxis(axisX)
self.int_line_serie.attachAxis(axisX)
axisX = QDateTimeAxis()
axisX.setFormat("yyyy-MM-dd")
self._chart.addAxis(axisX, Qt.AlignBottom)
self.dt_line_serie.attachAxis(axisX)
axisY = QValueAxis()
self._chart.addAxis(axisY, Qt.AlignLeft)
self._candlestick_serie.attachAxis(axisY)
self.dt_line_serie.attachAxis(axisY)
self.int_line_serie.attachAxis(axisY)
if __name__ == "__main__":
import sys
w = MainWindow()
w.show()
sys.exit(app.exec_())
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.