fft in python not showing peaks in right place

I'm trying to understand the numpy fft function, because my data reduction is acting weirdly. But now that I've transformed a simple sum of two sines, I get weird results. The peaks I have is extremely high and several points wide around zero, flattening the rest. Does anybody have a clue of what I might be doing wrong? import numpy as np from numpy import exp, sqrt, pi, linspace from

在python fft没有在正确的地方显示高峰

我试图了解numpy fft函数,因为我的数据简化是奇怪的。 但现在我已经改变了两个正弦的简单总和,我得到了奇怪的结果。 我拥有的高峰非常高,零点附近有几个点宽,其余部分变平。 有人知道我可能做错了吗? import numpy as np from numpy import exp, sqrt, pi, linspace from matplotlib import cm import matplotlib.pyplot as plt import scipy as sp import pylab #fourier tdata = np.arange(5999.)/300 datay = 3*np.

Calling python script from TCL and creating a file atomically

I wrote a python script that takes care of creating a file atomically as described in this other question. The file that gets created by the script is somewhat big (about ~1.5MB) as seen below: $ ./my_script.py --output_file some_directory/my_file.txt $ ls -l --block-size=K some_directory/my_file.txt -rw------- 1 foouser foogroup 1477K Aug 7 17:39 some_directory/my_file.txt Unfortunately, due

从TCL调用python脚本并自动创建一个文件

我写了一个python脚本,负责按照其他问题中所述的方式自动创建一个文件。 由脚本创建的文件有点大(约1.5MB),如下所示: $ ./my_script.py --output_file some_directory/my_file.txt $ ls -l --block-size=K some_directory/my_file.txt -rw------- 1 foouser foogroup 1477K Aug 7 17:39 some_directory/my_file.txt 不幸的是,由于一些遗留的基础设施和事情的设置方式,这个脚本需要从TCL脚本中调用。 以下是我目前正

Mapreduce job fails but not in test

I have a mapreduce job in Python that when I run it in test it works, but when I pass it through hadoop fails. I'm using a file I got from: wget http://stat-computing.org/dataexpo/2009/2008.csv.bz2 The map job is: #!/usr/bin/python import sys for line in sys.stdin: values = line.split(',') if values[13] != 'AirTime' and values[13] != 'NA': print '%s%st%st%s' % (values[8],

Mapreduce作业失败,但未进行测试

我在Python中有一个mapreduce作业,当我在测试中运行它时,它可以工作,但是当我通过hadoop时失败。 我正在使用我从以下文件获得的文件: wget http://stat-computing.org/dataexpo/2009/2008.csv.bz2 地图工作是: #!/usr/bin/python import sys for line in sys.stdin: values = line.split(',') if values[13] != 'AirTime' and values[13] != 'NA': print '%s%st%st%s' % (values[8], values[9], 'fligh

How to use python to read an encrypted folder

I want to design an application that reads some a folder of text files and shows the user its contents. Three problems arise: I need the folder containing the text files to be encrypted which I don't know how to do, two, I need a way to read the encrypted files without revealing the key in the python code, so I guess C would be the best way to do that even if I don't like that way(any su

如何使用python读取加密的文件夹

我想设计一个应用程序,它读取一些文本文件的文件夹并向用户显示其内容。 出现三个问题:我需要包含文本文件的文件夹进行加密,我不知道该怎么做,我需要一种方法来读取加密文件,而不会泄露python代码中的密钥,所以我猜C会即使我不喜欢这种方式,也是最好的方法(任何建议都欢迎,如果可能,请使用python),以及三种,我需要一种方法将文件添加到文件夹,然后将加密的文件夹与程序。 除了使用我的程序外,还有什么方法可以

how to set values on y axis in barchart

I am new to Python and I need to generate bar chart using pyplot and matplotlib. So far i tried like this (I have attached only the important code snippet): import matplotlib.pyplot as plt import numpy as np finalDataset=[finalAverage,final4Average] N=len(finalDataset) ind=np.arange(N) width=0.45 rects1=plt.bar(ind,finalDataset,width,color='blue') plt.xticks(in

如何在条形图中设置y轴上的值

我是Python的新手,我需要使用pyplot和matplotlib来生成条形图。 到目前为止,我尝试像这样(我只附加了重要的代码片段): import matplotlib.pyplot as plt import numpy as np finalDataset=[finalAverage,final4Average] N=len(finalDataset) ind=np.arange(N) width=0.45 rects1=plt.bar(ind,finalDataset,width,color='blue') plt.xticks(ind+width/2,("A","B")) plt.ylabel('y-ax

How to plot a histogram by different groups in matplotlib

I have a table like: value type 10 0 12 1 13 1 14 2 Generate a dummy data: import numpy as np value = np.random.randint(1, 20, 10) type = np.random.choice([0, 1, 2], 10) I want to accomplish a task in Python 3 with matplotlib (v1.4): plot a histogram of value group by type , ie use different colors to differentiate types the position of the "bars" s

如何绘制matplotlib中不同组的直方图

我有一张桌子,如: value type 10 0 12 1 13 1 14 2 生成一个虚拟数据: import numpy as np value = np.random.randint(1, 20, 10) type = np.random.choice([0, 1, 2], 10) 我想用matplotlib(v1.4)在Python 3中完成一项任务: 绘制value的直方图 按type分组,即使用不同的颜色来区分类型 “酒吧”的位置应该是“闪避”,即并排 由于价值的范围很小,因此我会使用箱子的identity ,即箱

Matplotlib Pyplot logo/image in Plot

I'm struggling to achieve a simple goal in matplotlib... I want to put a small logo or indicator in the bottom right of my graph, without altering the axis or the real data that is being displayed. Here is my code now: fig = plt.figure() plt.rcParams.update({'font.size': 15}) img = plt.imread('./path/to/image.png') ax1 = fig.add_subplot(111) ax1.yaxis.tick_left() ax1.tick_params(axis='y',

Matplotlib Pyplot标志/图中的情节

我正努力在matplotlib中实现一个简单的目标......我想在图形的右下方放一个小徽标或指示符,而不更改正在显示的轴或实际数据。 现在我的代码是: fig = plt.figure() plt.rcParams.update({'font.size': 15}) img = plt.imread('./path/to/image.png') ax1 = fig.add_subplot(111) ax1.yaxis.tick_left() ax1.tick_params(axis='y', colors='black', labelsize=15) ax1.tick_params(axis='x', colors='black', labelsize=15)

Plotting second figure with matplotlib while first is still open

K here's a more precise example of what I am trying to do. I am using WXBuilder for Python as my user interface with multiple plotting functionality ie the user must be able to plot a graph based on their chosen parameters. After a graph is plotted I want the user to be able to plot a second without closing the first figure. This is for comparison purposes. Below is an oversimplified exam

用matplotlib绘制第二个图时首先仍然打开

K这里是我正在尝试做的更精确的例子。 我使用WXBuilder for Python作为具有多个绘图功能的用户界面,即用户必须能够根据他们选择的参数绘制图表。 在绘制图形之后,我希望用户能够在不关闭第一个图形的情况下绘制第二个图形。 这是为了比较目的。 以下是我期待做的一个过于简单的例子。 导入matplotlib作为plt def OnPlotClick1(self,event): plt.plot(self.DateArray1,self.kVAArray2)plt.show() def OnPl

How to make IPython notebook matplotlib plot inline

I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0. I cannot get matplotlib graphics to show up inline. import matplotlib import numpy as np import matplotlib.pyplot as plt %matplotlib inline I have also tried %pylab inline and the ipython command line arguments --pylab=inline but this makes no difference. x = np.linspace(0, 3*np.pi, 500) plt.plot(x, np.sin(

如何使IPython笔记本matplotlib绘图内联

我试图在Python 2.7.2和IPython 1.1.0上使用MacOS X上的IPython笔记本。 我无法使matplotlib图形显示为内联。 import matplotlib import numpy as np import matplotlib.pyplot as plt %matplotlib inline 我也尝试了%pylab inline和ipython命令行参数--pylab=inline但这没什么区别。 x = np.linspace(0, 3*np.pi, 500) plt.plot(x, np.sin(x**2)) plt.title('A simple chirp') plt.show() 而不是内联图形,我得到这个:

Save plot to image file instead of displaying it using Matplotlib

I am writing a quick-and-dirty script to generate plots on the fly. I am using the code below (from Matplotlib documentation) as a starting point: from pylab import figure, axes, pie, title, show # Make a square figure and axes figure(1, figsize=(6, 6)) ax = axes([0.1, 0.1, 0.8, 0.8]) labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15, 30, 45, 10] explode = (0, 0.05, 0, 0) pie(fracs, explo

将绘图保存为图像文件,而不是使用Matplotlib显示它

我正在写一个快速而肮脏的脚本来动态生成剧情。 我使用下面的代码(来自Matplotlib文档)作为起点: from pylab import figure, axes, pie, title, show # Make a square figure and axes figure(1, figsize=(6, 6)) ax = axes([0.1, 0.1, 0.8, 0.8]) labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15, 30, 45, 10] explode = (0, 0.05, 0, 0) pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=