久久久久久久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 | 欧美日韩毛片 | 亚洲三级免费 | 国产tv | 亚洲在线播放 | 免费国产黄色 | 日本加勒比视频 | 国产成人毛片 | 97精品国产97久久久久久免费 | 天天躁日日躁bbbbb |