Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-108090

Qt chart does not show best fit line correctly

    XMLWordPrintable

Details

    • All
    • 2672db21a846c071cb31cfcfb974db5d837cfc42, 35abf0ef4 (6.4), 5404d9302 (tqtc/lts-6.2)

    Description

      from PyQt6 import QtWidgets
      from PyQt6 import QtCore
      from PyQt6 import QtGui
      from PyQt6.QtCore import Qt
      def create_chart(points, xrange, yrange):
          ch=QtCharts.QChart()
          cv=QtCharts.QChartView(ch)
          xaxis = QtCharts.QValueAxis()
          yaxis = QtCharts.QValueAxis()
          xaxis.setTickAnchor(1)
          xaxis.setTickInterval(1)
          xaxis.setRange(xrange[0], xrange[1])
          yaxis.setTickInterval(1)
          yaxis.setTickAnchor(1)
          yaxis.setRange(yrange[0], yrange[1])
          ch.addAxis(xaxis, Qt.AlignBottom)
          ch.addAxis(yaxis, Qt.AlignLeft)
          ss=QtCharts.QScatterSeries()
          ss.setBestFitLineVisible(True)
          for point in points:
              ss.append(point[0], point[1])
          ch.createDefaultAxes()
          ch.addSeries(ss)
          cv.show()
          return cv
        

      Case#1: Qt shows best fit line with this input.
      create_chart([[2, -26.957], [3, -23.022]], [1, 5], [-30, -20])

      Case#2: Qt does not show best fit line with this input
      create_chart([[ -26.957, 2], [-23.022, 3]], [-30, -20], [1, 5])

      The only difference is axis values are swapped.

      Attachments

        1. best fit line visible.png
          best fit line visible.png
          901 kB
        2. no best fit line when X and Y are reversed.png
          no best fit line when X and Y are reversed.png
          385 kB
        3. qtbug108090_diag.diff
          2 kB
        4. qtbug108090_log.txt
          2 kB
        5. qtbug108090.jpg
          qtbug108090.jpg
          89 kB
        6. qtbug108090.zip
          2 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              kleint Friedemann Kleint
              vipinjain Vipin Jain
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes