亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

由不滾動的 maplotlib 圖組成的 kivy scrollview

由不滾動的 maplotlib 圖組成的 kivy scrollview

holdtom 2023-03-30 16:42:42
我目前正在構建一個數字規劃器應用程序,我想在其中包含一些與統計相關的功能。顯然,matplotlib 是實現此目的的最佳方法,但是當我嘗試在 aa Kivy ScrollView 中添加多個圖時,我遇到了兩個問題:每個圖的大小都減小了很多,以至于您看不到實際顯示的內容;Kivy ScrollView 不滾動——不幸的是,這很常見。我已經嘗試將 ScrollView 的高度設置為 ScrollView.minimum_height,但我沒有得到任何結果。這是我的一些 Python 代碼:class StatsWindow(FloatLayout, MDTabsBase):    dates_from, dates_to, plot_scroll  = [str(datetime.today()).split()[0]], [str(datetime.today()).split()[0]], ObjectProperty(None)    def add_sp_plot(self, date_from, date_to):        # There were too many lines of data handling and plot creating, so I've only left the KivyPart:        # ------- KIVY part ------- KIVY part ------- KIVY part ------- KIVY part ------- #        self.plot_scroll.plot_layout.clear_widgets()        self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf(), size_hint_y=None))        self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf(), size_hint_y=None))        self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf(), size_hint_y=None))這是我的一些 Kivy 代碼:<StatsWindow>:    name: "stats"    text: "STATS"    icon: "thumbs-up-down"    plot_scroll: plot_scroll    choose_date_to: choose_date_to    choose_date_from: choose_date_from    FloatLayout:        MDLabel:            halign: "center"            size_hint: 1, .1            text: "Choose the dates to view your stats"            font_size: self.width / 17            color: app.theme_cls.primary_color            pos_hint: {"top": .98, "center_x": .5}        BoxLayout:            MDFlatButton:                id: choose_date_from                pos_hint: {"center_x": .25, "top": .88}                text: "from"                size_hint: .4, .1                font_size: self.width / 11                on_release: root.open_date_picker(root.dates_from, self)            MDFlatButton:                text: "|"                size_hint: .1, .1                pos_hint: {"center_x": .5, "top": .88}            MDFlatButton:                id: choose_date_to這是我運行程序時得到的圖片:
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

ScrollView僅當其子項 (the GridLayout) 大于 時才會滾動ScrollView。此外,該行:


height: self.minimum_height

除非您添加以下行,否則將無效:


size_hint_y: None

row_default_height您可以通過為指定 aGridLayout并為 消除 來size_hint_y=None增加繪圖的大小FigureCanvasKivyAgg。因此,我建議將您指定ScrollView為:


    ScrollView: 

        id: plot_scroll

        do_scroll_y: True

        do_scroll_x: False

        pos_hint: {"top": .68}

        plot_layout: plot_layout


        GridLayout:

            id: plot_layout

            cols: 1

            size_hint_y: None

            row_default_height: 500  # any default row height that you desire

            height: self.minimum_height

然后,使用以下方法添加繪圖:


def add_sp_plot(self, date_from, date_to):


    # There were too many lines of data handling and plot creating, so I've only left the KivyPart:

    # ------- KIVY part ------- KIVY part ------- KIVY part ------- KIVY part ------- #


    self.plot_scroll.plot_layout.clear_widgets()

    self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))

    self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))

    self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))

刪除size_hint_y=None保留默認值size_hint_yas 1,以便繪圖將占用GridLayout分配給它的所有空間 (the row_default_height)。


查看完整回答
反對 回復 2023-03-30
  • 1 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號