<legend id='Blkwi'><style id='Blkwi'><dir id='Blkwi'><q id='Blkwi'></q></dir></style></legend>
      <tfoot id='Blkwi'></tfoot>
          <bdo id='Blkwi'></bdo><ul id='Blkwi'></ul>
      1. <small id='Blkwi'></small><noframes id='Blkwi'>

        <i id='Blkwi'><tr id='Blkwi'><dt id='Blkwi'><q id='Blkwi'><span id='Blkwi'><b id='Blkwi'><form id='Blkwi'><ins id='Blkwi'></ins><ul id='Blkwi'></ul><sub id='Blkwi'></sub></form><legend id='Blkwi'></legend><bdo id='Blkwi'><pre id='Blkwi'><center id='Blkwi'></center></pre></bdo></b><th id='Blkwi'></th></span></q></dt></tr></i><div id='Blkwi'><tfoot id='Blkwi'></tfoot><dl id='Blkwi'><fieldset id='Blkwi'></fieldset></dl></div>

        如何将 yaxis 刻度标签设置在固定位置,以便当我

        时间:2023-08-07
        <i id='9sHSd'><tr id='9sHSd'><dt id='9sHSd'><q id='9sHSd'><span id='9sHSd'><b id='9sHSd'><form id='9sHSd'><ins id='9sHSd'></ins><ul id='9sHSd'></ul><sub id='9sHSd'></sub></form><legend id='9sHSd'></legend><bdo id='9sHSd'><pre id='9sHSd'><center id='9sHSd'></center></pre></bdo></b><th id='9sHSd'></th></span></q></dt></tr></i><div id='9sHSd'><tfoot id='9sHSd'></tfoot><dl id='9sHSd'><fieldset id='9sHSd'></fieldset></dl></div>

          <legend id='9sHSd'><style id='9sHSd'><dir id='9sHSd'><q id='9sHSd'></q></dir></style></legend>

            <tbody id='9sHSd'></tbody>
        1. <small id='9sHSd'></small><noframes id='9sHSd'>

          <tfoot id='9sHSd'></tfoot>
            <bdo id='9sHSd'></bdo><ul id='9sHSd'></ul>

                1. 本文介绍了如何将 yaxis 刻度标签设置在固定位置,以便当我向左或向右滚动时,yaxis 刻度标签应该可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的程序中,我先绘制了图,然后将图导入到画布中.然后我将画布导入滚动区域.当我运行我的程序时,如果我向左滚动 yaxis 刻度标签会隐藏,或者我向右滚动 yaxis 刻度标签也会隐藏.我采取了两个轴.轴,轴 2.我已经设置了 axes2.yaxis.tick_right() 和 axes.yaxis.tick_right().

                  in my program i have taken figure first then i import figue into canvas. Then i import canvas into scroll area. when i run my program ,then if i turn left scroll the yaxis tick label goes hide or i turn right scroll the yaxis tick label goes also hide. i have taken two axis. axis,axis2. i have set axes2.yaxis.tick_right() and axes.yaxis.tick_right().

                  我希望 yaxis 刻度标签将保持在右侧并且别名可见,无论我向左或向右滚动.

                  import sys
                  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
                  import matplotlib.pyplot as plt
                  from matplotlib.figure import Figure
                  from PyQt5.QtWidgets import QMainWindow,QVBoxLayout
                  from PyQt5.QtWidgets import QApplication
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  import datetime
                  from matplotlib.dates import num2date, date2num
                  from mpl_finance import candlestick_ochl as candlestick
                  import numpy as np
                  import matplotlib.ticker as ticker
                  import matplotlib.dates as mdates
                  import pylab as pl
                  class MainWindow_code_serarch(object):
                  
                      def setup_code_serarch(self, MainWindow):
                          MainWindow.setObjectName("MainWindow")
                          MainWindow.resize(870, 680)
                          self.centralwidget = QtWidgets.QWidget(MainWindow)
                          self.centralwidget.setObjectName("centralwidget")
                          self.verticalLayoutWidget1 = QtWidgets.QWidget(self.centralwidget)
                          self.verticalLayoutWidget1.setGeometry(QtCore.QRect(17, 30, 741, 13))
                          self.verticalLayoutWidget1.setObjectName("verticalLayoutWidget")
                          self.verticalLayout1 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget1)
                          self.verticalLayout1.setContentsMargins(0, 0, 0, 0)
                          self.verticalLayout1.setObjectName("verticalLayout1")
                          self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
                          self.verticalLayoutWidget.setGeometry(QtCore.QRect(17, 10, 940, 603))
                          self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
                          self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
                          self.verticalLayout.setContentsMargins(0, 0, 0, 0)
                          self.verticalLayout.setObjectName("verticalLayout")
                          self.figure = Figure(figsize=(100,7.2), dpi=80, facecolor='k')
                          self.canvas = FigureCanvas(self.figure)
                          self.widget = QtWidgets.QWidget()
                          self.scroll_area = QtWidgets.QScrollArea(self.widget)
                          self.scroll_area.setWidget(self.canvas)
                          self.verticalLayout.addWidget(self.scroll_area)
                          axes,axes2 = self.figure.subplots(nrows=2, sharex=True)
                          data = {
                              'date': ['2018/10/30', '2018/11/03', '2018/11/04', '2018/11/05', '2018/11/07', '2018/11/10', '2018/11/11'],
                              'open': [8824, 8726.31, 8642.14, 8531.51, 8630.25, 8602.50, 8640.22],
                              'high': [8858, 8748.60, 8551.36, 8653.16, 8476.69, 8630, 8570.56],
                              'low': [8688, 8743.67, 8550.76, 8449.50, 8631.83, 8602.18, 8743.22],
                              'close': [8820, 8747.17, 8550.52, 8553., 8517.10, 8628.78, 8588.52],
                              'volume': [17759.56, 120000.17, 18739.52, 38599.50, 16517.10, 17723.78, 15588.52]
                          }
                          x = date2num([datetime.datetime.strptime(d, '%Y/%m/%d').date() for d in data['date']])
                          t= np.arange(len(data['date']))
                          candle_trace = zip(t, data['open'], data['high'], data['low'], data['close'], data['volume'])
                          candlestick(axes, candle_trace, width=.75, colorup='g', colordown='r')
                          axes2.plot(t, [1, 2, 3, 4, 7, 8, 9])
                          axes.set_position([0.02, 0.37, 0.88, 0.6])
                          axes2.set_position([0.02, 0.15, 0.88, 0.22])
                          axes.tick_params(axis='both', color='#ffffff', labelcolor='#ffffff')
                          axes.yaxis.tick_right()
                          axes2.tick_params(axis='both', color='#ffffff', labelcolor='#ffffff')
                          axes2.grid(color='lightgray', linewidth=.5, linestyle=':')
                          axes.grid(color='lightgray', linewidth=.5, linestyle=':')
                          axes2.yaxis.tick_right()
                          axes.autoscale_view()
                          axes2.autoscale_view()
                          axes.set_facecolor('#041105')
                          axes2.set_facecolor('#041105')
                          # N = len(dates)
                          axes.set_xticks(range(0, len((x)), 1))
                          axes.set_xticklabels([mdates.num2date(d).strftime('%b-%d') for d in x])
                          axes.set_xticklabels([mdates.num2date(d).strftime('%Y-%m-%d') for d in x])
                          axes2.set_xticklabels([mdates.num2date(d).strftime('%Y-%m-%d') for d in x])
                          self.canvas.draw()
                          MainWindow.setCentralWidget(self.centralwidget)
                          self.menubar = QtWidgets.QMenuBar(MainWindow)
                          self.menubar.setGeometry(QtCore.QRect(0, 0, 246, 21))
                          self.menubar.setObjectName("menubar")
                          MainWindow.setMenuBar(self.menubar)
                          self.statusbar = QtWidgets.QStatusBar(MainWindow)
                          self.statusbar.setObjectName("statusbar")
                          MainWindow.setStatusBar(self.statusbar)
                          # self.pushButton.clicked.connect(self.graphShowCode)
                  
                          self.retranslateUi(MainWindow)
                          QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                      def retranslateUi(self, MainWindow):
                          _translate = QtCore.QCoreApplication.translate
                          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
                          # self.pushButton.setText(_translate("MainWindow", "OK"))
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      MainWindow = QtWidgets.QMainWindow()
                      ui = MainWindow_code_serarch()
                      ui.setup_code_serarch(MainWindow)
                      MainWindow.show()
                      sys.exit(app.exec_())
                  

                  输出图像:

                  当我向左滚动输出图像 2:

                  when i turn scroll left output image 2:

                  推荐答案

                  这是一种使用 PyQt QtScrollBar 滚动轴内容的方法.这是通过根据滚动条的值更改轴的限制来完成的.为此,注册了对 QtScrollBaractionTriggered 方法的回调,该方法会更改坐标轴的限制.

                  Here is a way to scroll the content of an axes with a PyQt QtScrollBar. This is done by changing the limits of the axes depending on the scroll bar's value. To this end, a callback to the QtScrollBar's actionTriggered method is registered that changes the limits of the axes.

                  import sys
                  import matplotlib
                  # Make sure that we are using QT5
                  matplotlib.use('Qt5Agg')
                  import matplotlib.pyplot as plt
                  from PyQt5 import QtWidgets, QtCore
                  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
                  from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
                  import numpy as np
                  
                  class ScrollableWindow(QtWidgets.QMainWindow):
                      def __init__(self, fig, ax, step=0.1):
                          plt.close("all")
                          if not QtWidgets.QApplication.instance():
                              self.app = QtWidgets.QApplication(sys.argv)
                          else:
                              self.app = QtWidgets.QApplication.instance() 
                  
                          QtWidgets.QMainWindow.__init__(self)
                          self.widget = QtWidgets.QWidget()
                          self.setCentralWidget(self.widget)
                          self.widget.setLayout(QtWidgets.QVBoxLayout())
                          self.widget.layout().setContentsMargins(0,0,0,0)
                          self.widget.layout().setSpacing(0)
                  
                          self.fig = fig
                          self.ax = ax
                          self.canvas = FigureCanvas(self.fig)
                          self.canvas.draw()
                          self.scroll = QtWidgets.QScrollBar(QtCore.Qt.Horizontal)
                          self.step = step
                          self.setupSlider()
                          self.nav = NavigationToolbar(self.canvas, self.widget)
                          self.widget.layout().addWidget(self.nav)
                          self.widget.layout().addWidget(self.canvas)
                          self.widget.layout().addWidget(self.scroll)
                  
                          self.canvas.draw()
                          self.show()
                          self.app.exec_()
                  
                      def setupSlider(self):
                          self.lims = np.array(self.ax.get_xlim())
                          self.scroll.setPageStep(self.step*100)
                          self.scroll.actionTriggered.connect(self.update)
                          self.update()
                  
                      def update(self, evt=None):
                          r = self.scroll.value()/((1+self.step)*100)
                          l1 = self.lims[0]+r*np.diff(self.lims)
                          l2 = l1 +  np.diff(self.lims)*self.step
                          self.ax.set_xlim(l1,l2)
                          print(self.scroll.value(), l1,l2)
                          self.fig.canvas.draw_idle()
                  
                  
                  # create a figure and some subplots
                  fig, ax = plt.subplots()
                  t = np.linspace(0,3000,101)
                  x = np.cumsum(np.random.randn(len(t)))
                  ax.plot(t,x, marker="o")
                  
                  # pass the figure to the custom window
                  a = ScrollableWindow(fig,ax)
                  

                  对于图中的滚动条,请参阅可滚动条形图matplotlib

                  For a Scrollbar within the figure, see Scrollable Bar graph matplotlib

                  这篇关于如何将 yaxis 刻度标签设置在固定位置,以便当我向左或向右滚动时,yaxis 刻度标签应该可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:`QImage` 构造函数有未知关键字 `data` 下一篇:PyQt 启动后进度跃升至 100%

                  相关文章

                  最新文章

                  <small id='1vdWo'></small><noframes id='1vdWo'>

                  • <bdo id='1vdWo'></bdo><ul id='1vdWo'></ul>
                  1. <legend id='1vdWo'><style id='1vdWo'><dir id='1vdWo'><q id='1vdWo'></q></dir></style></legend>
                  2. <i id='1vdWo'><tr id='1vdWo'><dt id='1vdWo'><q id='1vdWo'><span id='1vdWo'><b id='1vdWo'><form id='1vdWo'><ins id='1vdWo'></ins><ul id='1vdWo'></ul><sub id='1vdWo'></sub></form><legend id='1vdWo'></legend><bdo id='1vdWo'><pre id='1vdWo'><center id='1vdWo'></center></pre></bdo></b><th id='1vdWo'></th></span></q></dt></tr></i><div id='1vdWo'><tfoot id='1vdWo'></tfoot><dl id='1vdWo'><fieldset id='1vdWo'></fieldset></dl></div>
                    1. <tfoot id='1vdWo'></tfoot>