簡體   English   中英

Python Matplotlib,干圖不適用於FuncAnimation

[英]Python Matplotlib, Stem plot not working with FuncAnimation

我正在嘗試繪制來自傳入數據包的實時數據。 我有一個子圖上的四個子圖,我想將數據繪制為莖圖,但是我收到以下錯誤:
self.stemlines.set_data(z,y)AttributeError:“列表”對象沒有屬性“ set_data”

plt.plot可以正常工作,但是我無法將其用於plt.steam。

import matplotlib

matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
import matplotlib


class PlotEngine:

    def __init__(self, axisChanged):
        # plt.style.use('seaborn-whitegrid')
        # style.use('fivethirtyeight')
        initialMinValue = '14.4'
        initialMaxValue = '14.9'

        plt.style.use('ggplot')
        matplotlib.rc('axes', titlesize=8)  # fontsize of the axes title
        matplotlib.rc('axes', labelsize=8)
        matplotlib.rc('xtick', labelsize=8)  # fontsize of the tick labels
        matplotlib.rc('ytick', labelsize=8)  # fontsize of the tick labels   axes.titlesize
        matplotlib.rc('figure', titlesize=8)

        self.fig, self.ax = plt.subplots(2, 2)
        plt.ion()
        # plt.subplot(2, 2, 4, polar=True)
        self.fig.patch.set_facecolor('gray')
        self.axpolar = plt.subplot(2, 2, 4, projection='polar')
        self.axpolar.set_facecolor('black')
        # self.ax[1, 1] = fig.add_subplot(2, 2, 4, projection='polar')
        self.ax[0, 0].set_facecolor('black')
        self.ax[0, 1].set_facecolor('black')
        self.ax[1, 0].set_facecolor('black')
        self.ax[1, 1].set_facecolor('black')

        self.axisChanged = axisChanged
        self.slider_freq = plt.axes([0.1, 0.01, 0.3, 0.01])
        self.slider_azi = plt.axes([0.5, 0.01, 0.3, 0.01])
        self.freqAxBoxMin = plt.axes([0.55, 0.33, 0.04, 0.03])
        self.freqAxBoxMax = plt.axes([0.55, 0.28, 0.04, 0.03])
        self.freqMinValueBox = TextBox(self.freqAxBoxMin, 'Min Freq:', initial=initialMinValue)
        self.freqMaxValueBox = TextBox(self.freqAxBoxMax, 'Max Freq:', initial=initialMaxValue)
        self.aziAxBoxMin = plt.axes([0.55, 0.18, 0.04, 0.03])
        self.aziAxBoxMax = plt.axes([0.55, 0.10, 0.04, 0.03])
        self.aziMinValueBox = TextBox(self.aziAxBoxMin, 'Min Dir:', initial='-180')
        self.aziMaxValueBox = TextBox(self.aziAxBoxMax, 'Max Dir:', initial='180')
        self.zeroOne, = self.ax[0, 1].plot([], [], 'ro')
        self.oneOne, = self.axpolar.plot([], [], 'ro')
        self.markerline, self.stemlines, self.baseline, = self.ax[1, 0].stem([1], [1], bottom=-140)
        self.ax[0, 1].set_xlim([0, 60])
        self.ax[0, 1].set_ylim([-140, -40])
        self.axpolar.set_yticks(range(-90, -30, 10))  # Define the yticks
        # self.axpolar.set_yticklabels(map(str, range(-90, -30, -10)))  # Change the labels
        self.ax[1, 0].set_xlim([14, 14.8])
        self.ax[1, 0].set_ylim([-140, -40])

    # self.background = fig.canvas.copy_from_bbox(self.ax.bbox)

    def animateZeroOne(self, i, azimuth, rss, freqGhz):
        x = azimuth
        y = rss
        z = freqGhz

        self.zeroOne.set_data(x, y)
        self.oneOne.set_data(x, y)
        self.stemlines.set_data(z, y)
        self.markerline.set_data(z, y)

        return self.zeroOne, self.oneOne, self.stemlines, self.markerline

根據StemContainerstemlinesLine2D的列表,因此它不具有set_data屬性,例如markerlinebaselineLine2D類型)。 也許您想將該函數應用於animateZeroOne函數的列表的每個成員上?

    def animateZeroOne(self, i, azimuth, rss, freqGhz):
        x = azimuth
        y = rss
        z = freqGhz

        self.zeroOne.set_data(x, y)
        self.oneOne.set_data(x, y)
        [x.set_data(z, y) for x in self.stemlines]
        self.markerline.set_data(z, y)

        return self.zeroOne, self.oneOne, self.stemlines, self.markerline

暫無
暫無

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

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