簡體   English   中英

如何在圖表中顯示我的情節?

[英]How to display my plot in the graph?

您好,我的python代碼有問題。 我想創建一個圖,為此,我有一個按鈕,我想要的是當我單擊該按鈕時,在所需的圖形上獲得了該圖。 現在我得到的是一個圖,但是在按鈕上!

這是我的代碼:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button

class Index(objects):
    ind = 0
    def next(self,event):
        a = np.array([1,2,3,4,5])
        b = np.array([15,20,1,3,5])
        v = plt.plot(a,b)


callback = Index()
axnext = plt.axes([0.0, 0.90, 0.1, 0.075])
bnext = Button(axnext, 'Plot')
bnext.on_clicked(callback.next)

plt.show()

謝謝您的幫助 !

好的,我想我已經解決了:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button

figure, ax1 = plt.subplots()

class Index(object):

    ind = 0

    def next(self, event):    
        a = np.array([1,2,3,4,5])
        b = np.array([15,20,1,3,5])
        ax1.plot(a,b)


callback = Index()
axnext = plt.axes([0.0, 0.90, 0.1, 0.075])
bnext = Button(axnext, 'Plot')
bnext.on_clicked(callback.next)

plt.show()

所以在這里,我將class Index(objects) class Index(object)更改為class Index(objects) class Index(object) 我還在類之前定義了一個圖形和一些簡單的軸,這意味着您可以繪制該圖形。 沒有它,似乎在“繪圖”按鈕內繪制圖形。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM