久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Matplotlib 顯示頁面上的滾動條

Scrollbar on Matplotlib showing page(Matplotlib 顯示頁面上的滾動條)
本文介紹了Matplotlib 顯示頁面上的滾動條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道是否有辦法將滾動條(水平或垂直)放在 matplotlib 顯示頁面(plt.show)上,該頁面包含多個子批次(sublot2grid).目前,我找到的唯一解決方案是使子圖非常小,這根本不是很優雅.

I want to know if there is a manner to put a scrollbar (horizontal or vertical) on a matplotlib showing page (plt.show) that contains several sublots (sublot2grid). At the moment, the only solution I find is to make the subplots very small, which isn't very elegant at all.

推薦答案

顯示matplotlib圖的窗口沒有添加滾動條的選項.它會自動將自己調整為圖形大小.相反,如果調整大小,圖形也會調整大小.

The window showing the matplotlib figure does not have the option to add scrollbars. It will automatically resize itself to the figure size. And inversely, if it is resized the figure will resize as well.

一個選項是構建一個具有此功能的自定義窗口.為此,可以使用 PyQt.下面給出了一個示例,其中不是調用 plt.show() 而是調用自定義類,并將圖形作為參數進行繪制.圖形大小應事先設置為圖形 fig 并且該自定義類不會更改它.相反,它將圖形放入帶有滾動條的畫布中,以便圖形保持其原始大小并且可以在 Qt 窗口中滾動.您不必處理類中的細節,只需處理腳本末尾的調用即可.

An option would be to build a custom window which does have this ability. For that purpose, one can use PyQt. An example is given below, where instead of calling plt.show() a custom class is called with the figure to draw as an argument. The figure size should be set to the figure fig beforehands and that custom class will not change it. Instead it puts the figure into a canvas with scrollbars, such that the figure retains it's original size and can be scrolled within the Qt window. You wouln't have to deal with the details inside the class but only the call at the end of the script.

此示例適用于 PyQt4,請參閱下面的 PyQt5 示例.

This example is for PyQt4, see below for a PyQt5 example.

import matplotlib.pyplot as plt
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar

class ScrollableWindow(QtGui.QMainWindow):
    def __init__(self, fig):
        self.qapp = QtGui.QApplication([])

        QtGui.QMainWindow.__init__(self)
        self.widget = QtGui.QWidget()
        self.setCentralWidget(self.widget)
        self.widget.setLayout(QtGui.QVBoxLayout())
        self.widget.layout().setContentsMargins(0,0,0,0)
        self.widget.layout().setSpacing(0)

        self.fig = fig
        self.canvas = FigureCanvas(self.fig)
        self.canvas.draw()
        self.scroll = QtGui.QScrollArea(self.widget)
        self.scroll.setWidget(self.canvas)

        self.nav = NavigationToolbar(self.canvas, self.widget)
        self.widget.layout().addWidget(self.nav)
        self.widget.layout().addWidget(self.scroll)

        self.show()
        exit(self.qapp.exec_()) 


# create a figure and some subplots
fig, axes = plt.subplots(ncols=4, nrows=5, figsize=(16,16))
for ax in axes.flatten():
    ax.plot([2,3,5,1])

# pass the figure to the custom window
a = ScrollableWindow(fig)

<小時>這是 PyQt5 的版本.

import matplotlib
# Make sure that we are using QT5
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from PyQt5 import QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar


class ScrollableWindow(QtWidgets.QMainWindow):
    def __init__(self, fig):
        self.qapp = QtWidgets.QApplication([])

        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.canvas = FigureCanvas(self.fig)
        self.canvas.draw()
        self.scroll = QtWidgets.QScrollArea(self.widget)
        self.scroll.setWidget(self.canvas)

        self.nav = NavigationToolbar(self.canvas, self.widget)
        self.widget.layout().addWidget(self.nav)
        self.widget.layout().addWidget(self.scroll)

        self.show()
        exit(self.qapp.exec_()) 


# create a figure and some subplots
fig, axes = plt.subplots(ncols=4, nrows=5, figsize=(16,16))
for ax in axes.flatten():
    ax.plot([2,3,5,1])

# pass the figure to the custom window
a = ScrollableWindow(fig)


雖然此答案顯示了一種滾動完整圖形的方法,但如果您對 滾動軸的內容感興趣,請查看 這個答案

這篇關于Matplotlib 顯示頁面上的滾動條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 色接久久| 国产传媒毛片精品视频第一次 | 一起操网站 | 免费黄色av | 九九热精品视频 | 日韩精品一区二区三区 | 西西裸体做爰视频 | 久久久久国色av免费观看性色 | 欧美三级电影在线播放 | 亚洲视频免费观看 | 亚洲国产精品一区二区第一页 | 精品国产免费人成在线观看 | 国产视频一区二区在线观看 | 亚洲午夜小视频 | 天天操 天天操 | 欧美一级全黄 | 99福利在线观看 | 成人国产在线视频 | 四虎成人av | 日韩久久网 | 久久精品女人天堂av | 欧美嘿咻| 99久久精品国产一区二区三区 | 亚洲成人免费视频 | 国产99久久久国产精品 | 日韩成人免费av | 亚洲欧美一区在线 | 天天草天天干 | 97精品超碰一区二区三区 | xx视频在线观看 | 亚洲成人精品免费 | 中文字幕精品一区久久久久 | 精品国产一级片 | www.天天操| 国产欧美视频一区二区 | 中文字幕亚洲一区 | 91免费观看在线 | 一区二区三区四区不卡视频 | 亚洲精品一 | 国产一区二区三区 | 午夜视频在线观看网址 |