Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to show the top number of the y-axis in Qchart?
Forum Updated to NodeBB v4.3 + New Features

How to show the top number of the y-axis in Qchart?

Scheduled Pinned Locked Moved Solved Qt for Python
11 Posts 4 Posters 1.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • feiyuhuahuoF Offline
    feiyuhuahuoF Offline
    feiyuhuahuo
    wrote on last edited by
    #1

    0cfa075c-78f6-46e9-bcb5-b97ed46dd5e9-image.png
    The top number of the y-axis is missed. How to solve this?

    S 1 Reply Last reply
    0
    • feiyuhuahuoF feiyuhuahuo

      0cfa075c-78f6-46e9-bcb5-b97ed46dd5e9-image.png
      The top number of the y-axis is missed. How to solve this?

      S Offline
      S Offline
      StarterKit
      wrote on last edited by
      #2

      @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.

      ndiasN 1 Reply Last reply
      0
      • S StarterKit

        @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.

        ndiasN Offline
        ndiasN Offline
        ndias
        wrote on last edited by
        #3

        I think, it depends on data point contained on the series.
        On my side, sometimes this number is visible and sometimes not.

        S 1 Reply Last reply
        0
        • ndiasN ndias

          I think, it depends on data point contained on the series.
          On my side, sometimes this number is visible and sometimes not.

          S Offline
          S Offline
          StarterKit
          wrote on last edited by StarterKit
          #4

          @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 and max_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 of step between lo_limit and hi_limit.

          1 Reply Last reply
          1
          • feiyuhuahuoF Offline
            feiyuhuahuoF Offline
            feiyuhuahuo
            wrote on last edited by
            #5

            @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.

            S 1 Reply Last reply
            0
            • feiyuhuahuoF Offline
              feiyuhuahuoF Offline
              feiyuhuahuo
              wrote on last edited by
              #6

              @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

              1 Reply Last reply
              0
              • feiyuhuahuoF feiyuhuahuo

                @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.

                S Offline
                S Offline
                StarterKit
                wrote on last edited by StarterKit
                #7

                @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:
                example

                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...

                ndiasN 1 Reply Last reply
                0
                • S StarterKit

                  @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:
                  example

                  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...

                  ndiasN Offline
                  ndiasN Offline
                  ndias
                  wrote on last edited by ndias
                  #8

                  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.

                  96ea6e76-ccbd-4b27-83e0-6740cb806338-image.png

                  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

                  1 Reply Last reply
                  2
                  • feiyuhuahuoF Offline
                    feiyuhuahuoF Offline
                    feiyuhuahuo
                    wrote on last edited by
                    #9

                    @StarterKit My OS is win10 and I'm the same case as the right chart of @ndias. So there maybe a bug.

                    1 Reply Last reply
                    0
                    • feiyuhuahuoF Offline
                      feiyuhuahuoF Offline
                      feiyuhuahuo
                      wrote on last edited by
                      #10

                      @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.

                      eyllanescE 1 Reply Last reply
                      2
                      • feiyuhuahuoF feiyuhuahuo

                        @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.

                        eyllanescE Offline
                        eyllanescE Offline
                        eyllanesc
                        wrote on last edited by
                        #11

                        @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.

                        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                        1 Reply Last reply
                        2

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved