首页 \ 问答 \ JavaScript:未命名函数的参数(JavaScript: parameters for unnamed functions)

JavaScript:未命名函数的参数(JavaScript: parameters for unnamed functions)

在下面的jQuery JavaScript代码中,参数“e”在函数内具有什么值? 我很难理解这个,因为这个函数不能在代码的其他地方传递一个参数,所以如何让参数有效? 我怎样才能在这些没有命名的函数中使用参数,而不是在代码的其他地方调用?

    $(document).ready( function() { 
        $('div').each(function() {
            $(this).click(function(e){
                //some code
            });
        });
    });

In the following jQuery JavaScript code, what value does the parameter "e" take on within the function? I'm having difficulty understanding this because this function cannot be passed an argument elsewhere in the code so how would having a parameter work? And how would I use parameters in such functions that are not named and not called anywhere else in the code?

    $(document).ready( function() { 
        $('div').each(function() {
            $(this).click(function(e){
                //some code
            });
        });
    });

原文:https://stackoverflow.com/questions/419144
更新时间:2023-03-26 20:03

最满意答案

我相信你需要通过matplotlib.use()函数将matplotlib后端更改为wx,以便在wx图形中嵌入matplotlib图。

这是我在您的脚本中更改的内容:

import matplotlib
matplotlib.use('WX')
import matplotlib.pyplot as plt

这在测试后产生了以下图像:

Test.png

控制台输出:

Initialize subplots
Creating ax1
Creating ax2
Creating ax3
Creating ax4
***** Saving plot to: /Users/luccary/Downloads/foo/Test_[0].png
/Users/luccary/.virtualenvs/numpy/lib/python2.7/site-packages/matplotlib/cbook.py:136: MatplotlibDeprecationWarning: The WX backend is deprecated. It's untested and will be removed in Matplotlib 2.2. Use the WXAgg backend instead. See Matplotlib usage FAQ for more info on backends.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Test Done

请注意弃用警告,因为wx将作为Matplotlib 2.2中的后端删除,您应该使用wxagg代替。

参考文献:请参阅此matplotlib教程 ,我在此处阅读了类似问题的Stack Overflow回答后找到了该教程

希望这能回答你的问题。 祝你好运!


I believe you need to change the matplotlib backend to wx via the matplotlib.use() function in order to embed matplotlib plots within wx graphics.

Here's what I changed in your script:

import matplotlib
matplotlib.use('WX')
import matplotlib.pyplot as plt

This produced the following image after testing:

Test.png

Console output:

Initialize subplots
Creating ax1
Creating ax2
Creating ax3
Creating ax4
***** Saving plot to: /Users/luccary/Downloads/foo/Test_[0].png
/Users/luccary/.virtualenvs/numpy/lib/python2.7/site-packages/matplotlib/cbook.py:136: MatplotlibDeprecationWarning: The WX backend is deprecated. It's untested and will be removed in Matplotlib 2.2. Use the WXAgg backend instead. See Matplotlib usage FAQ for more info on backends.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Test Done

Please note the deprecation warning, since wx will be removed as a backend in Matplotlib 2.2, and you should likely use wxagg instead.

References: See this matplotlib tutorial which I found after reading a Stack Overflow answer to a similar question here.

Hope that answers your question. Good luck!

相关问答

更多
  • 这是该示例的改进版本。 (免责声明:我半小时前开始深入挖掘它,从未使用过wx / matplotlib滚动条,因此可能有更好的解决方案。) 我采取的路径:首先我检查了wx滚动事件 ,然后发现画布是从wxPanel派生的FigureCanvasWxAgg,继承了wxWindow方法。 在那里你可以找到滚动位置处理方法GetScrollPos和SetScrollPos 。 from numpy import arange, sin, pi, float, size import matplotlib matp ...
  • 这是在Jupyter笔记本或类似的东西? 通常你不应该这样做 matplotlib.use('QT4Agg') import matplotlib 按照该顺序,因为matplotlib不会在名称空间中。 更改顺序,然后重新启动Jupyter内核或将所有这些转储到.py文件中。 在Jupyter,你应该可以打电话 %matplotlib qt4 在导入matplotlib来设置后端而不是调用use()之前 。 Is this in Jupyter Notebook or something of the ...
  • 使用pd.to_datetime将timedetlas转换为datetime 。 它会在1970年给所有的东西一个日期,但如果你想要的只是绘制和显示,那么它就不重要了。 然后您需要摆脱.dt.total_seconds() 。 import pandas as pd import matplotlib.pyplot as plt from matplotlib.dates import DateFormatter, date2num df = pd.DataFrame({'Year':[2010, 201 ...
  • 我相信你需要通过matplotlib.use()函数将matplotlib后端更改为wx,以便在wx图形中嵌入matplotlib图。 这是我在您的脚本中更改的内容: import matplotlib matplotlib.use('WX') import matplotlib.pyplot as plt 这在测试后产生了以下图像: 控制台输出: Initialize subplots Creating ax1 Creating ax2 Creating ax3 Creating ax4 ***** S ...
  • 我不太了解你的问题,如果你正试图在qt图形上显示图像,请尝试先用下面的函数保存它。 plt.savefig('image1.png', transparent = True, bbox_inches = 'tight', pad_inches = 0) 那么您可以使用像素图并设置场景以显示在图形视图中。 I don't really understand your question, if you are trying to display an image on qt graphics, try sav ...
  • 这是你想要的吗? import matplotlib.pyplot as plt import numpy as np if __name__ == "__main__": fig, ax = plt.subplots(1, 1) theta = np.linspace(0, 2*np.pi, 1024) ln, = ax.plot(theta, np.sin(theta)) plt.ion() plt.show(block=False) while Tr ...
  • 第一个错误,“致命的Python错误:GC对象已经跟踪”于2013年关闭,状态为“CLOSED WONTFIX”请参阅Bugzilla的错误报告 在2015年[与dask相关]再次提出的临时解决方案似乎是使用此代码使用单个线程 : import dask dask.set_options(get=dask.async.get_sync) 但问题实际上存在于dataframe.read_csv问题。 这个问题最终在后来的熊猫版本中得到了解决 。 如果您升级matplotlib的版本,问题很可能也 ...
  • 有几个选项:一个是使用mpl 示例的很好的例子 。 第二个是写你自己的循环,这样你就可以理解发生了什么。 这是一个使用pylab.draw()函数而不是show()的简单示例,它不是很花哨,但它可以让你理解基本的东西: import pylab import time pylab.ion() # animation on # Note the comma after line. This is placed here because # plot returns a list of lines tha ...
  • 首先,请注意pyplot不是线程安全的。 然后:使用“Agg”-backend进行非交互式创建多个图像。 一个工作示例(由于线程可能出现问题)是: import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from numpy import arange, sin, pi import threading class Dummy(): def plotme(self, iteration = 1): ...
  • 就像典型的情况一样,写一个问题的行为激励我去研究一种我以前没想过的可能性。 x数据正在更新,但绘图范围不是。 当我在图上放置新数据时,它全都超出了范围。 解决方案是添加: ax.relim() ax.autoscale_view(True,True,True) (部分参考) 这是原始问题的上下文中的代码,希望有一天它会对其他人有所帮助: import matplotlib.pyplot as plt import matplotlib.dates as mdate import numpy as np ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)