I managed to set the x and y axes separately for the line graph.
It was not possible to install separate axes for QCandlestickSeries.

I need to do two things:
1. Set separate axes for Candlestickseries to adjust parameter axisX.setTickCount()
2. Display the x-axis converted datetime to string, instead of indexes

P.S. At least the example on the line graph from my second(2) question will do.

Qt Code:
  1. from PyQt5 import QtCore, QtGui, QtWidgets, QtChart
  2. from PyQt5.QtCore import Qt
  3. from PyQt5.QtChart import *
  4. import math
  5. import numpy as np
  6. import pandas as pd
  7.  
  8. df = pd.read_csv('file.txt',
  9. index_col='DATE',
  10. parse_dates=True,
  11. infer_datetime_format=True)
  12.  
  13. date = df.iloc[:, 0].index.date
  14. o = df.iloc[:, 0].values
  15. h = df.iloc[:, 1].values
  16. l = df.iloc[:, 2].values
  17. z = df.iloc[:, 3].values
  18. x = len(z)
  19. x_ = x - 1
  20.  
  21. qt = [None] * x
  22. for i in range(0, x):
  23. qt[i] = (date[i].strftime("%Y/%m/%d"))
  24.  
  25. class MainWindow(QtWidgets.QMainWindow):
  26. def __init__(self, parent=None):
  27. super().__init__(parent)
  28.  
  29. self.step = 30
  30. self._chart_view = QtChart.QChartView()
  31. self.scrollbar = QtWidgets.QScrollBar(
  32. QtCore.Qt.Horizontal,
  33. sliderMoved=self.onAxisSliderMoved,
  34. pageStep=self.step,
  35. )
  36.  
  37. self.scrollbar.setRange(0, x_)
  38.  
  39. central_widget = QtWidgets.QWidget()
  40. self.setCentralWidget(central_widget)
  41.  
  42. lay = QtWidgets.QVBoxLayout(central_widget)
  43. for w in (self._chart_view, self.scrollbar):
  44. lay.addWidget(w)
  45.  
  46. self._chart = QtChart.QChart()
  47. self._line_serie = QtChart.QLineSeries()
  48.  
  49. for i in range(0, len(z)):
  50. c_ = z[i]
  51. self._line_serie.append(QtCore.QPointF(i, c_))
  52.  
  53. min_x, max_x = 0, x_
  54. self._chart.addSeries(self._line_serie)
  55.  
  56. axisX = QValueAxis()
  57. axisX.setTickCount(5)
  58. axisX.setLabelFormat("%d")
  59. self._chart.addAxis(axisX, Qt.AlignBottom)
  60. self._line_serie.attachAxis(axisX)
  61.  
  62. axisY = QValueAxis()
  63. #axisY.setLabelFormat("%f")
  64. self._chart.addAxis(axisY, Qt.AlignLeft)
  65. self._line_serie.attachAxis(axisY)
  66.  
  67. self._chart.legend().hide()
  68. self._chart_view.setChart(self._chart)
  69. self.lims = np.array([min_x, max_x])
  70. self.onAxisSliderMoved(self.scrollbar.value())
  71. self.adjust_axes(1, 31)
  72.  
  73. def adjust_axes(self, value_min, value_max):
  74. if value_min > 0 and value_max > 0 and value_max <= x_ and value_max > value_min:
  75. self._chart.axisX(self._line_serie).setRange(value_min, value_max)
  76.  
  77. @QtCore.pyqtSlot(int)
  78. def onAxisSliderMoved(self, value):
  79. value2 = value + self.step
  80. value1 = value
  81. if value2 >= x_:
  82. value2 = x_
  83. value1 = value2 - self.step
  84. self.adjust_axes(math.floor(value1), math.ceil(value2))
  85.  
  86.  
  87. if __name__ == "__main__":
  88. import sys
  89.  
  90. app = QtWidgets.QApplication(sys.argv)
  91. w = MainWindow()
  92. w.show()
  93. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode