How to show the top number of the y-axis in Qchart?
-
The top number of the y-axis is missed. How to solve this? -
@feiyuhuahuo May you show your code please?
I started to play with QCharts yesterday and did an example very similar to yours. But I didn't have this problem with my simple code. So I suspect it is something special with your data or your code. -
I think, it depends on data point contained on the series.
On my side, sometimes this number is visible and sometimes not. -
@ndias probably you are right.
I like to have some "round" numbers on a chart so I usually do something like this:
from math import log10, floor, ceil step = 10 ** floor(log10(max_value - min_value)) lo_limit = floor(min_value / step) * step hi_limit = ceil(max_value / step) * step axisY.setTickCount(11) axisY.setRange(lo_limit, hi_limit)
here
min_value
andmax_value
are minimum and maximum values from displayed series.
The code finds closest power of 10 for delta between min and max and then uses it to round borders.
Tick count is set to 11 in order to have 10 intervals that usually looks nice but it may be linked to number ofstep
betweenlo_limit
andhi_limit
. -
@StarterKit , @ndias
I have code like this:from PySide6.QtGui import QPainter from PySide6.QtWidgets import QApplication from PySide6.QtCharts import QChartView, QChart, QLineSeries, QValueAxis from PySide6.QtCore import Qt if __name__ == '__main__': app = QApplication() chart = QChart() series = QLineSeries(chart) chart.addSeries(series) series.append(1, 6) series.append(2, 4) x_axis = QValueAxis() y_axis = QValueAxis() chart.addAxis(x_axis, Qt.AlignBottom) chart.addAxis(y_axis, Qt.AlignLeft) series.attachAxis(x_axis) series.attachAxis(y_axis) x_axis.setRange(0, 5) y_axis.setRange(0, 10) # y_axis.setTickCount(6) view = QChartView(chart) view.setRenderHint(QPainter.Antialiasing) # 抗锯齿 view.resize(800, 600) view.show() app.exec()
Could you help me solve the problem? The two data points are all in range of the x axis and y axis. But that number just don't show. I'm confused.
-
@StarterKit ,@ndias
And I found all the official examples are the same case as mine.
Like this: https://doc.qt.io/qtforpython-6/examples/example_charts__chartthemes.html -
@feiyuhuahuo It is interesting....
I still have PySide2 (PySide6 have some features to be ready this fall only).
I made very small changes to your code:x_axis.setRange(1, 2) y_axis.setRange(4, 6) y_axis.setTickCount(6)
And it looks good:
So my suspect would be not about PySide2 vs PySide6 difference but rather about platform difference... Which OS do you use?
I tried on Linux and Win10 - the result is the same... -
Hi @StarterKit and @feiyuhuahuo ,
I tested, on Win10 OS, using pyside2 (left) and pyside6 (right) and in fact there seems to be a difference between the two versions. It's likely a regression.
I checked the bug report system but I haven't found any bugs reported on the subject. Maybe we can open a new report with this issue providing a minimal script reproducing the issue so the Qt team can analyze it.
Regards
-
@StarterKit My OS is win10 and I'm the same case as the right chart of @ndias. So there maybe a bug.
-
@ndias The bug seems to be repaired in a latest version. https://bugreports.qt.io/browse/QTBUG-94998
But it seems not available for pip. -
@feiyuhuahuo According to the bug the solution will be available in 5.15.6 and Qt 6.2. I don't know if there will be a new release of PySide2 but if of PySide6 so you just have to wait since Qt 6.2 is still in beta.