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
最满意答案
我相信你需要通过
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 ***** 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:
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!
相关问答
更多-
Matplotlib:滚动图(Matplotlib: scrolling plot)[2023-05-15]
这是该示例的改进版本。 (免责声明:我半小时前开始深入挖掘它,从未使用过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 ...
-
Matplotlib多处理(Matplotlib multiProcessing)[2023-02-19]
这是你想要的吗? 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): ...
-
更新matplotlib图(update matplotlib plot)[2023-01-07]
就像典型的情况一样,写一个问题的行为激励我去研究一种我以前没想过的可能性。 x数据正在更新,但绘图范围不是。 当我在图上放置新数据时,它全都超出了范围。 解决方案是添加: ax.relim() ax.autoscale_view(True,True,True) (部分参考) 这是原始问题的上下文中的代码,希望有一天它会对其他人有所帮助: import matplotlib.pyplot as plt import matplotlib.dates as mdate import numpy as np ...