首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python,Stem绘图不使用FuncAnimation

Python,Stem绘图不使用FuncAnimation
EN

Stack Overflow用户
提问于 2018-11-29 19:00:51
回答 1查看 591关注 0票数 0

我试图从输入的数据包中绘制实时数据。我有四个子图,在其中一个子图上,我想将数据绘制为Stem图,但是我收到了以下错误:

self.stemlines.set_data(z,y) AttributeError:'list‘对象没有属性'set_data'

plt.plot工作得很好,但我无法让它为plt.steam工作。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2018-11-29 19:56:53

根据StemContainerstemlines是一个列表( Line2D),因此它没有属性set_data,比如markerlinebaseline (类型为Line2D)。也许您想在animateZeroOne函数中对列表中的每个成员应用该函数?:

代码语言:javascript
复制
    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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53545866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档