【问题标题】:Trying to update a 3D graphs coordinates with matplotlib尝试使用 matplotlib 更新 3D 图形坐标
【发布时间】:2011-05-10 00:40:03
【问题描述】:

我有一个函数可以在 tkinter 中使用 matplotlib 绘制 3D 球体。然而,每次我将函数称为绕球体运行时的性能下降。此外,图表仅在我尝试绕球体运行后才会更新。

self.A 是一个调整球体大小的变量。

我的功能:

def draw_fig(self):

        self.ax = Axes3D(self.fig)

        u = numpy.linspace(0, 2 * numpy.pi, 100)
        v = numpy.linspace(0, numpy.pi, 100)
        x = self.A * numpy.outer(numpy.cos(u), numpy.sin(v))
        y = self.A * numpy.outer(numpy.sin(u), numpy.sin(v))
        z = self.A * numpy.outer(numpy.ones(numpy.size(u)), numpy.cos(v))

        t = self.ax.plot_surface(x, y, z,  rstride=4, cstride=4,color='lightblue',linewidth=0)

【问题讨论】:

    标签: python tkinter matplotlib


    【解决方案1】:

    你不应该每次都重新生成所有数据,而只是修改你现有的。

    编辑:只需移出调用 draw_fig 的轴构建代码

    def __init__...
         u = numpy.linspace(0, 2 * numpy.pi, 100)
         v = numpy.linspace(0, numpy.pi, 100)
         self.x = A * numpy.outer(numpy.cos(u), numpy.sin(v))
         self.y = A * numpy.outer(numpy.sin(u), numpy.sin(v))
         self.z = A * numpy.outer(numpy.ones(numpy.size(u)), numpy.cos(v))
         self.ax = Axes3D(self.fig)
    
    def draw_fig(self):
    
            t = self.ax.plot_surface(self.x, self.y, self.z,  rstride=4, cstride=4,color='lightblue',linewidth=0)
    

    【讨论】:

    • 我将如何实现这一点? self.A 也是一个整数,可以是 10 或 5。
    猜你喜欢
    • 2011-04-22
    • 1970-01-01
    • 2011-07-07
    • 2017-03-17
    • 2016-08-17
    • 2017-01-16
    • 2012-01-20
    • 2015-10-13
    • 1970-01-01
    相关资源
    最近更新 更多