Re: how to plot the FFT of a list of values

2020-12-07 Thread Thomas Jollans

On 05/12/2020 23:08, Christian Gollwitzer wrote:

Am 05.12.20 um 18:16 schrieb Boris Dorestand:

I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ...  I
compute its fourier transform using


from scipy import fft, ifft
x = [1,2,4,8,1,2,4,8]
fft(x)

array([ 30. +0.j,   0. +0.j,  -6.+12.j,   0. +0.j, -10. +0.j, 0. +0.j,
 -6.-12.j,   0. +0.j])

Now how can I plot these values?  I would like to plot 16 values.  What
do I need to do here?  Can you show an example?



Usually, for the FFT of real input data, you plot only the magnitude 
or square of the complex array, and usually on a logscale. So:


import pylab


Don't use pylab.

https://matplotlib.org/api/index.html#module-pylab

Use matplotlib.pyplot directly instead. "plt" is a popular shorthand:

from matplotlib import pyplot as plt

#...

plt.semilogy(...) # or plt.plot, etc.


- Thomas



import numpy as np

fx = fft(x)

pylab.semilogy(np.abs(fx))
pylab.show()



Christian





--
https://mail.python.org/mailman/listinfo/python-list


Re: how to plot the FFT of a list of values

2020-12-05 Thread Christian Gollwitzer

Am 05.12.20 um 18:16 schrieb Boris Dorestand:

I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ...  I
compute its fourier transform using


from scipy import fft, ifft
x = [1,2,4,8,1,2,4,8]
fft(x)

array([ 30. +0.j,   0. +0.j,  -6.+12.j,   0. +0.j, -10. +0.j,   0. +0.j,
 -6.-12.j,   0. +0.j])

Now how can I plot these values?  I would like to plot 16 values.  What
do I need to do here?  Can you show an example?



Usually, for the FFT of real input data, you plot only the magnitude or 
square of the complex array, and usually on a logscale. So:


import pylab
import numpy as np

fx = fft(x)

pylab.semilogy(np.abs(fx))
pylab.show()



Christian



--
https://mail.python.org/mailman/listinfo/python-list


Re: how to plot the FFT of a list of values

2020-12-05 Thread Dan Stromberg
On Sat, Dec 5, 2020 at 9:20 AM Boris Dorestand 
wrote:

> I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ...  I
> compute its fourier transform using
>
> >>> from scipy import fft, ifft
> >>> x = [1,2,4,8,1,2,4,8]
> >>> fft(x)
> array([ 30. +0.j,   0. +0.j,  -6.+12.j,   0. +0.j, -10. +0.j,   0. +0.j,
>     -6.-12.j,   0. +0.j])
>
> Now how can I plot these values?  I would like to plot 16 values.  What
> do I need to do here?  Can you show an example?
>

Maybe
https://stackoverflow.com/questions/17445720/how-to-plot-complex-numbers-argand-diagram-using-matplotlib
?
-- 
https://mail.python.org/mailman/listinfo/python-list


how to plot the FFT of a list of values

2020-12-05 Thread Boris Dorestand
I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ...  I
compute its fourier transform using

>>> from scipy import fft, ifft
>>> x = [1,2,4,8,1,2,4,8]
>>> fft(x)
array([ 30. +0.j,   0. +0.j,  -6.+12.j,   0. +0.j, -10. +0.j,   0. +0.j,
-6.-12.j,   0. +0.j])

Now how can I plot these values?  I would like to plot 16 values.  What
do I need to do here?  Can you show an example?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-14 Thread George Fischhof
Elliott Roper  ezt írta (időpont: 2019. aug. 14., Sze
15:56):

> On 14 Aug 2019, Elliott Roper wrote
> (in article<0001hw.23044901039e772c7ca97...@news.giganews.com>):
>
> > On 14 Aug 2019, amirrezaheidary...@gmail.com wrote
> > (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>):
> >
> > > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2,
> amirrezah...@gmail.com
> > > wrote:
>
> Oh Damn! Here is an attempt to stop the code running into a single line..
> > >
> > > > I have a .csv file, in first column I have date and hour, and in the
> second
> > > > column I have energy use data. How can I make a bar chart with Date
> and
> > > > time as the x axis and the energy use as the Y axis?
> > > >
> > > > Thanks
> > >
> > > Thank you for your guidance. I am already using matplotlib but I do
> not know
> > > how to import a column of date and time and to use it properly as the x
> > > axis.
> > > can you tell me the code?
> > >
> > > Thanks
>
> >
> > If you don't mind using a steam hammer to crack a nut, it is amazing
> what you
> > can do with pandas using just the "10 minute guide" chapter in the
> (shudder)
> > 10,000 page manual. The chief benefit is how thoroughly it protects you
> from
> > Numpy and Matplotlib.
> > I solved a similar problem (tracking home blood pressure with
> exponentially
> > weighted means) up and running in half a day from a completely cold
> start.
> > The graphing bit is a delight. However, if you want to do something that
> the
> > 10 minute guide does not cover, you can lose a man-month without really
> > trying. Pandas is a beautiful monster!
> >
> > Here's the relevant bit
> >
> > import numpy as np
> >
> > import pandas as pd
> >
> > import matplotlib.pyplot as plt
> >
> >
> > #preparing the csv from a text file elided as irrelevant
> >
> > #except that the .csv headings have to be Date Systolic Diastolic for
> this to
> > work as designed
> >
> > # Plot the intermediate file with pandas after adding exponentially
> weighted
> > means
> >
> > df = pd.read_csv('Blood pressure.csv')
> >
> > df['Date'] = pd.to_datetime(df['Date'])
> >
> > df['Syst EWM'] = df['Systolic'].ewm(span=200).mean()
> >
> > df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean()
> >
> > plt.ioff()
> >
> > df.plot(x='Date')
> >
> > print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more
> > healthy levels
> >
> > plt.ylabel('mm Hg')
> >
> > plt.suptitle("Home BP record")
> >
> > plt.show()
> >
> > That should give you a start
>
> --
> To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96
> 3CF7
> 637F 896B C810 E199 7E5C A9E4 8E59 E248
>
> --
> https://mail.python.org/mailman/listinfo/python-list




Hi,

Pygal is a very good and easy to use charting library

BR,
George


>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-14 Thread Elliott Roper
On 14 Aug 2019, Elliott Roper wrote
(in article<0001hw.23044901039e772c7ca97...@news.giganews.com>):

> On 14 Aug 2019, amirrezaheidary...@gmail.com wrote
> (in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>):
>
> > On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com
> > wrote:

Oh Damn! Here is an attempt to stop the code running into a single line..
> >
> > > I have a .csv file, in first column I have date and hour, and in the 
> > > second
> > > column I have energy use data. How can I make a bar chart with Date and
> > > time as the x axis and the energy use as the Y axis?
> > >
> > > Thanks
> >
> > Thank you for your guidance. I am already using matplotlib but I do not know
> > how to import a column of date and time and to use it properly as the x
> > axis.
> > can you tell me the code?
> >
> > Thanks

>
> If you don't mind using a steam hammer to crack a nut, it is amazing what you
> can do with pandas using just the "10 minute guide" chapter in the (shudder)
> 10,000 page manual. The chief benefit is how thoroughly it protects you from
> Numpy and Matplotlib.
> I solved a similar problem (tracking home blood pressure with exponentially
> weighted means) up and running in half a day from a completely cold start.
> The graphing bit is a delight. However, if you want to do something that the
> 10 minute guide does not cover, you can lose a man-month without really
> trying. Pandas is a beautiful monster!
>
> Here's the relevant bit
>
> import numpy as np
>
> import pandas as pd
>
> import matplotlib.pyplot as plt
>
>
> #preparing the csv from a text file elided as irrelevant
>
> #except that the .csv headings have to be Date Systolic Diastolic for this to
> work as designed
>
> # Plot the intermediate file with pandas after adding exponentially weighted
> means
>
> df = pd.read_csv('Blood pressure.csv')
>
> df['Date'] = pd.to_datetime(df['Date'])
>
> df['Syst EWM'] = df['Systolic'].ewm(span=200).mean()
>
> df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean()
>
> plt.ioff()
>
> df.plot(x='Date')
>
> print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more
> healthy levels
>
> plt.ylabel('mm Hg')
>
> plt.suptitle("Home BP record")
>
> plt.show()
>
> That should give you a start

-- 
To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 
637F 896B C810 E199 7E5C A9E4 8E59 E248

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-14 Thread Elliott Roper
On 14 Aug 2019, amirrezaheidary...@gmail.com wrote
(in article<23d45668-fa47-4640-832a-5a5c64600...@googlegroups.com>):

> On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com
> wrote:
> > I have a .csv file, in first column I have date and hour, and in the second
> > column I have energy use data. How can I make a bar chart with Date and
> > time as the x axis and the energy use as the Y axis?
> >
> > Thanks
>
> Thank you for your guidance. I am already using matplotlib but I do not know
> how to import a column of date and time and to use it properly as the x axis.
> can you tell me the code?
>
> Thanks

If you don't mind using a steam hammer to crack a nut, it is amazing what you 
can do with pandas using just the "10 minute guide" chapter in the (shudder) 
10,000 page manual. The chief benefit is how thoroughly it protects you from 
Numpy and Matplotlib.
I solved a similar problem (tracking home blood pressure with exponentially 
weighted means) up and running in half a day from a completely cold start. 
The graphing bit is a delight. However, if you want to do something that the 
10 minute guide does not cover, you can lose a man-month without really 
trying. Pandas is a beautiful monster!

Here's the relevant bit

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pytz
from pytz import common_timezones, all_timezones

#preparing the csv from a text file elided as irrelevant
#except that the .csv headings have to be Date Systolic Diastolic for this to 
work as designed

# Plot the intermediate file with pandas after adding exponentially weighted 
means
df = pd.read_csv('Blood pressure.csv')
df['Date'] = pd.to_datetime(df['Date'])
df['Syst EWM'] = df['Systolic'].ewm(span=200).mean()
df['Diast EWM'] = df['Diastolic'].ewm(span=200).mean()
plt.ioff()
df.plot(x='Date')
print(df.tail(60)) #a debug line I left in to watch the EWMs sink to more 
healthy levels
plt.ylabel('mm Hg')
plt.suptitle("Home BP record")
plt.show()

That should give you a start
-- 
To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 
637F 896B C810 E199 7E5C A9E4 8E59 E248

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-14 Thread amirrezaheidarysbu
On Tuesday, August 13, 2019 at 11:47:28 PM UTC+2, amirrezah...@gmail.com wrote:
> I have a .csv file, in first column I have date and hour, and in the second 
> column I have energy use data. How can I make a bar chart with Date and time 
> as the x axis and the energy use as the Y axis?
> 
> Thanks

Thank you for your guidance. I am already using matplotlib but I do not know 
how to import a column of date and time and to use it properly as the x axis. 
can you tell me the code?


Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-13 Thread Chris Angelico
On Wed, Aug 14, 2019 at 8:17 AM Rich Shepard  wrote:
>
> On Tue, 13 Aug 2019, amirrezaheidary...@gmail.com wrote:
>
> > I have a .csv file, in first column I have date and hour, and in the
> > second column I have energy use data. How can I make a bar chart with Date
> > and time as the x axis and the energy use as the Y axis?
>
> First, find yourself a plotting program (R and PSTricks are two I use;
> matplotlib also does a fine job).

Given that we're on python-list here, matplotlib would be the obvious
choice here :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot a data including date and time?

2019-08-13 Thread Rich Shepard

On Tue, 13 Aug 2019, amirrezaheidary...@gmail.com wrote:


I have a .csv file, in first column I have date and hour, and in the
second column I have energy use data. How can I make a bar chart with Date
and time as the x axis and the energy use as the Y axis?


First, find yourself a plotting program (R and PSTricks are two I use;
matplotlib also does a fine job). Second, learn what data format and
manipulation that application uses on provided data. Third, learn that
application/language and plot your data after importing it to the
application.

Rich
--
https://mail.python.org/mailman/listinfo/python-list


How to plot a data including date and time?

2019-08-13 Thread amirrezaheidarysbu
I have a .csv file, in first column I have date and hour, and in the second 
column I have energy use data. How can I make a bar chart with Date and time as 
the x axis and the energy use as the Y axis?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot

2017-10-27 Thread Andrew Z
 Rrhank you Thomas.

On Oct 27, 2017 04:23, "Thomas Jollans"  wrote:

> On 2017-10-27 07:18, Andrew Z wrote:
> > Hello,
> >  i'd like to create a graph/plot based a DB table's data, but not sure
> > where to start. I
> >
> >  also would like to have the following functionality:
> >  a. i'd like to have it in the separate window ( xwindow to be precise).
> >  b. and i'd like to have the graph updating with every record added to
> the
> > table.
> >
> > The workflow:
> >  a. main code is running and occasionally adding records to the table
> >  b. graph gets updated "automagically" and is shown in a separate from
> the
> > main terminal window.
> >
> > Main program does not have GUI, nor is Web based, just runs in the
> terminal
> > on Xwindows.
> >
> > i don't' really care about cross-platform compability and only want to
> run
> > that on linux xwindows.
> >
> > Thank you for your advise.
> >
>
> Matplotlib  is the standard Python plotting
> library, and it has GUI backends (Tk, Qt, Gtk, ...) that should be
> perfectly suitable for your purposes.
>
> The API maybe takes some getting used to, but there are plenty of
> examples to be found around the web, and the main documentation is quite
> good.
>
> If you need the plots to update quickly (it doesn't sound like it) then
> you might need to luck into something else, like pyqtgraph or vispy.
>
>
> --
> Thomas Jollans
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to plot

2017-10-27 Thread Thomas Jollans
On 2017-10-27 07:18, Andrew Z wrote:
> Hello,
>  i'd like to create a graph/plot based a DB table's data, but not sure
> where to start. I
> 
>  also would like to have the following functionality:
>  a. i'd like to have it in the separate window ( xwindow to be precise).
>  b. and i'd like to have the graph updating with every record added to the
> table.
> 
> The workflow:
>  a. main code is running and occasionally adding records to the table
>  b. graph gets updated "automagically" and is shown in a separate from the
> main terminal window.
> 
> Main program does not have GUI, nor is Web based, just runs in the terminal
> on Xwindows.
> 
> i don't' really care about cross-platform compability and only want to run
> that on linux xwindows.
> 
> Thank you for your advise.
> 

Matplotlib  is the standard Python plotting
library, and it has GUI backends (Tk, Qt, Gtk, ...) that should be
perfectly suitable for your purposes.

The API maybe takes some getting used to, but there are plenty of
examples to be found around the web, and the main documentation is quite
good.

If you need the plots to update quickly (it doesn't sound like it) then
you might need to luck into something else, like pyqtgraph or vispy.


-- 
Thomas Jollans
-- 
https://mail.python.org/mailman/listinfo/python-list


How to plot

2017-10-26 Thread Andrew Z
Hello,
 i'd like to create a graph/plot based a DB table's data, but not sure
where to start. I

 also would like to have the following functionality:
 a. i'd like to have it in the separate window ( xwindow to be precise).
 b. and i'd like to have the graph updating with every record added to the
table.

The workflow:
 a. main code is running and occasionally adding records to the table
 b. graph gets updated "automagically" and is shown in a separate from the
main terminal window.

Main program does not have GUI, nor is Web based, just runs in the terminal
on Xwindows.

i don't' really care about cross-platform compability and only want to run
that on linux xwindows.

Thank you for your advise.
-- 
https://mail.python.org/mailman/listinfo/python-list