• <bdo id='kHmYQ'></bdo><ul id='kHmYQ'></ul>

    <small id='kHmYQ'></small><noframes id='kHmYQ'>

    <legend id='kHmYQ'><style id='kHmYQ'><dir id='kHmYQ'><q id='kHmYQ'></q></dir></style></legend>
    1. <tfoot id='kHmYQ'></tfoot>
      <i id='kHmYQ'><tr id='kHmYQ'><dt id='kHmYQ'><q id='kHmYQ'><span id='kHmYQ'><b id='kHmYQ'><form id='kHmYQ'><ins id='kHmYQ'></ins><ul id='kHmYQ'></ul><sub id='kHmYQ'></sub></form><legend id='kHmYQ'></legend><bdo id='kHmYQ'><pre id='kHmYQ'><center id='kHmYQ'></center></pre></bdo></b><th id='kHmYQ'></th></span></q></dt></tr></i><div id='kHmYQ'><tfoot id='kHmYQ'></tfoot><dl id='kHmYQ'><fieldset id='kHmYQ'></fieldset></dl></div>
      1. Matplotlib:带有滑块小部件的等高线图

        Matplotlib: contour plot with slider widget(Matplotlib:带有滑块小部件的等高线图)
          <tfoot id='f0tea'></tfoot>
              <tbody id='f0tea'></tbody>
            • <bdo id='f0tea'></bdo><ul id='f0tea'></ul>

                <small id='f0tea'></small><noframes id='f0tea'>

                <i id='f0tea'><tr id='f0tea'><dt id='f0tea'><q id='f0tea'><span id='f0tea'><b id='f0tea'><form id='f0tea'><ins id='f0tea'></ins><ul id='f0tea'></ul><sub id='f0tea'></sub></form><legend id='f0tea'></legend><bdo id='f0tea'><pre id='f0tea'><center id='f0tea'></center></pre></bdo></b><th id='f0tea'></th></span></q></dt></tr></i><div id='f0tea'><tfoot id='f0tea'></tfoot><dl id='f0tea'><fieldset id='f0tea'></fieldset></dl></div>

              1. <legend id='f0tea'><style id='f0tea'><dir id='f0tea'><q id='f0tea'></q></dir></style></legend>

                1. 本文介绍了Matplotlib:带有滑块小部件的等高线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  新手 matplotlib 用户在这里.我正在尝试使用滑块来调整等高线图中的参数,但是当我这样做时,我得到:

                  Newbie matplotlib user here. I'm trying to use a slider to adjust a parameter in a contour plot, but when I do so, I get:

                  AttributeError: QuadContourSet instance has no attribute 'set_data'
                  

                  我怀疑我在错误的对象上调用 set_data,但我找不到任何关于 right 对象是什么的文档.你能帮我吗?谢谢.

                  I suspect that I'm calling set_data on the wrong object, but I can't find any documentation on what the right object is. Can you help? Thanks.

                  这是完整的代码:

                  import numpy as np
                  import matplotlib as mpl
                  import matplotlib.mlab as mlab
                  import matplotlib.pyplot as pyl
                  from matplotlib.contour import QuadContourSet
                  from matplotlib.widgets import Slider
                  
                  #Define display parameters
                  mpl.rcParams['xtick.direction'] = 'out'
                  mpl.rcParams['ytick.direction'] = 'out'
                  delta = 0.025
                  
                  #Define model parameters
                  alpha = .5
                  beta = .5
                  x_bar, a, b, c = 2, 0, 1, .1
                  v = np.arange(0, 10, delta)
                  w = np.arange(0, 10, delta)
                  
                  #Calculate grid values
                  V, W = np.meshgrid(v,w)
                  Z = (V**(beta))*(W**(1-beta))
                  X = x_bar + a + b*Z
                  U = alpha*np.log(V) + (1-alpha)*np.log(X) - c*(W+V)
                  
                  # Plot
                  fig = pyl.figure()
                  
                  ax = fig.add_subplot(221)
                  CS = QuadContourSet(pyl.gca(), V, W, U, 200)
                  pyl.clabel(CS, inline=1, fontsize=10)
                  pyl.title('Simplest default with labels')
                  
                  #Define slider for alpha
                  axcolor = 'lightgoldenrodyellow'
                  alpha_axis  = pyl.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
                  alpha_slider = Slider(alpha_axis, 'Amp', 0, 1, valinit=.5)
                  
                  def update(val):
                      alpha = alpha_slider.val
                      U = alpha*np.log(V) + (1-alpha)*np.log(X) - c*(W+V)
                      CS.set_data(V, W, U)
                      pyl.draw()
                  
                  alpha_slider.on_changed(update)
                  
                  pyl.show()
                  

                  推荐答案

                  问题是 QuadContourSet 对象没有办法更新它的数据,因为如果你随意更改数据,整个事情都需要重新计算.我不知道您生成数据的特定方式是否有助于以更简单的方式修改等高线,但如果没有,我认为您需要做的是从头开始绘制等高线:

                  The problem is that the QuadContourSet object has no way to update its data, since if you change the data arbitrarily, the whole thing needs to be recomputed. I don't know if there is something about your particular way of generating data that would lend itself to a simpler way to modify the contour lines, but if not, I think what you need to do is to plot the contours from scratch:

                  # After your "Define model parameters" block
                  
                  def compute_and_plot(ax, alpha):
                      #Calculate grid values
                      V, W = np.meshgrid(v,w)
                      Z = (V**(beta))*(W**(1-beta))
                      X = x_bar + a + b*Z
                      U = alpha*np.log(V) + (1-alpha)*np.log(X) - c*(W+V)
                  
                      CS = QuadContourSet(ax, V, W, U, 200)
                      pyl.clabel(CS, inline=1, fontsize=10)
                  
                  # Plot
                  fig = pyl.figure()
                  pyl.title('Simplest default with labels')
                  ax = fig.add_subplot(221)
                  compute_and_plot(ax, alpha)
                  
                  #Define slider for alpha
                  axcolor = 'lightgoldenrodyellow'
                  alpha_axis  = pyl.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
                  alpha_slider = Slider(alpha_axis, 'Amp', 0, 1, valinit=.5)
                  
                  def update(ax, val):
                      alpha = alpha_slider.val
                      ax.cla()
                      compute_and_plot(ax, alpha)
                      pyl.draw()
                  
                  alpha_slider.on_changed(lambda val: update(ax, val))
                  
                  pyl.show()
                  

                  这篇关于Matplotlib:带有滑块小部件的等高线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  <legend id='ojKqf'><style id='ojKqf'><dir id='ojKqf'><q id='ojKqf'></q></dir></style></legend>
                    <bdo id='ojKqf'></bdo><ul id='ojKqf'></ul>
                      <tbody id='ojKqf'></tbody>

                            <tfoot id='ojKqf'></tfoot>
                            <i id='ojKqf'><tr id='ojKqf'><dt id='ojKqf'><q id='ojKqf'><span id='ojKqf'><b id='ojKqf'><form id='ojKqf'><ins id='ojKqf'></ins><ul id='ojKqf'></ul><sub id='ojKqf'></sub></form><legend id='ojKqf'></legend><bdo id='ojKqf'><pre id='ojKqf'><center id='ojKqf'></center></pre></bdo></b><th id='ojKqf'></th></span></q></dt></tr></i><div id='ojKqf'><tfoot id='ojKqf'></tfoot><dl id='ojKqf'><fieldset id='ojKqf'></fieldset></dl></div>

                          1. <small id='ojKqf'></small><noframes id='ojKqf'>