Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17970

Re: Plot seems weird

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'desired.': 0.07; 'infinite': 0.07; 'transform': 0.07; '>>>>': 0.09; 'filename': 0.09; 'graph': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; '25,': 0.12; 'am,': 0.12; 'def': 0.13; '[[],': 0.16; 'already.': 0.16; 'filenames': 0.16; 'numpy': 0.16; 'pyplot': 0.16; 'rectangle': 0.16; 'smoothly,': 0.16; 'this:': 0.16; "wouldn't": 0.17; 'wrote:': 0.18; '>>>': 0.18; 'interesting.': 0.18; 'ryan': 0.18; 'convert': 0.19; 'seems': 0.20; 'trying': 0.21; 'maybe': 0.21; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'thus': 0.23; 'produces': 0.23; 'scale': 0.25; 'code': 0.25; '(like': 0.26; 'import': 0.27; 'code,': 0.27; 'all,': 0.28; 'weird': 0.29; 'fixed': 0.29; 'looks': 0.29; 'pm,': 0.29; 'efficiently': 0.30; 'thanks': 0.31; 'header:User-Agent:1': 0.33; 'header:X-Complaints- To:1': 0.33; 'to:addr:python-list': 0.34; 'file.': 0.34; 'things': 0.34; 'anything': 0.34; 'leaves': 0.34; 'lie': 0.34; 'record': 0.35; 'something': 0.35; 'be.': 0.35; 'supposed': 0.35; 'apply': 0.35; 'test': 0.35; 'file': 0.36; 'data.': 0.36; 'received:au': 0.36; 'but': 0.37; 'run': 0.37; 'signal': 0.38; 'received:org': 0.38; 'feed': 0.39; 'should': 0.39; "couldn't": 0.39; 'data,': 0.39; 'johnson': 0.39; 'to:addr:python.org': 0.40; 'might': 0.40; 'more': 0.61; 'your': 0.61; 'lower': 0.64; 'believe': 0.65; 'due': 0.66; '26,': 0.67; 'square': 0.67; 'exact': 0.68; '04:08': 0.84; 'fault,': 0.84; 'transitions,': 0.84; 'url:tinypic': 0.91; 'working,': 0.93; 'received:110': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Lie Ryan <lie.1296@gmail.com>
Subject Re: Plot seems weird
Date Tue, 27 Dec 2011 05:58:43 +1100
References <880a2ed3-1a3f-45e7-b439-e87289403fd9@t16g2000vba.googlegroups.com> <c1ae9905-da26-4513-a456-99941ac53036@dp8g2000vbb.googlegroups.com> <4f709686-4b07-4096-a87c-3e4bf8571c73@v13g2000yqc.googlegroups.com> <mailman.4099.1324891710.27778.python-list@python.org> <74f9b578-ab36-4962-a353-ec52fe5ba12e@cs7g2000vbb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 110-175-240-90.static.tpgi.com.au
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0
In-Reply-To <74f9b578-ab36-4962-a353-ec52fe5ba12e@cs7g2000vbb.googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4104.1324925950.27778.python-list@python.org> (permalink)
Lines 98
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324925950 news.xs4all.nl 6895 [2001:888:2000:d::a6]:55033
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17970

Show key headers only | View raw


On 12/27/2011 04:08 AM, Yigit Turgut wrote:
> On Dec 26, 11:28 am, Lie Ryan<lie.1...@gmail.com>  wrote:
>> On 12/26/2011 05:27 AM, Yigit Turgut wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Dec 25, 7:06 pm, Rick Johnson<rantingrickjohn...@gmail.com>    wrote:
>>>> On Dec 25, 9:33 am, Yigit Turgut<y.tur...@gmail.com>    wrote:
>>>>> Hi all,
>>
>>>>> I have a text file as following;
>>
>>>>> 0.200047        0.000000
>>>>> 0.200053        0.160000
>>>>> 0.200059        0.000000
>>>>> 0.200065        0.080000
>>>>> 0.200072        0.000000
>>>>> 0.200078        0.160000
>>
>>>>> And I am trying to plot it with ;
>>
>>>>> filenames = sys.argv[1:]
>>>>> if len(filenames) == 0:
>>>>>       filenames = [sys.stdin]
>>>>> for filename in filenames:
>>>>>       t,y1 = numpy.genfromtxt(filename, unpack=True)
>>>>>       pyplot.plot(t,y1)
>>>>>       pyplot.show()
>>
>>>>> But graph seems weird, not as it supposed to be. Any ideas ?
>>
>>>> Interesting. Of course "weird" leaves a LOT to be desired. On a scale
>>>> of 1-10, how "weird" is the result?
>>
>>> I apply a 1Khz test signal just to see if things run smoothly, but I
>>> see spikes at lower and higher ends (logic 0,1) where I should see a
>>> clean rectangle pwm signal. By the look of it I say weirdness is
>>> around 3/10.
>>
>> What are you expecting? Your data produces something that looks like the
>> plot on the right of this screenshot
>> (http://i44.tinypic.com/wwhlvp.jpg), I don't see anything weird with
>> that; if you are expecting a square-wave-like plot (like on the left),
>> then you should use a square-wave-like data, pyplot wouldn't magically
>> transform a spiked-plot to squared-plot.
>>
>> Here's what I use to convert the data on right plot to data on left
>> plot, I don't know much about numpy so it might be possible to do it
>> more efficiently or numpy might even have something like it already.
>>
>> from itertools import izip_longest
>> def to_square(t, y1):
>>       sq_data = [[], []]
>>       for x,y, xn in izip_longest(data[0], data[1], data[0][1:]):
>>           sq_data[0].append(x)
>>           sq_data[1].append(y)
>>           sq_data[0].append(xn)
>>           sq_data[1].append(y)
>>       return numpy.array(sq_data, dtype=float)
>
> Thanks for the tip. I know that I feed a square wave signal and record
> this data. Thus I believe the situation can be related to sampling
> frequency.

It is due to sampling frequency, but also because you cannot sample a 
square wave perfectly because square wave has infinite steepness at the 
transitions. Although if you know the exact timing of the transitions, 
it may be possible to reconstruct the transitions perfectly.

> Couldn't get your code working, maybe because I import the data from
> file.

not your fault, I made a mistake when copy-pasteing the code, here's the 
fixed code:

from itertools import izip_longest
def to_square(data):
      sq_data = [[], []]
      for x,y, xn in izip_longest(data[0], data[1], data[0][1:]):
          sq_data[0].append(x)
          sq_data[1].append(y)
          sq_data[0].append(xn)
          sq_data[1].append(y)
      return numpy.array(sq_data, dtype=float)


use it like this:

t,y1 = to_square(numpy.genfromtxt(filename, unpack=True))
pyplot.plot(t,y1)
pyplot.show()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Plot seems weird Yigit Turgut <y.turgut@gmail.com> - 2011-12-25 07:33 -0800
  Re: Plot seems weird Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-25 09:06 -0800
    Re: Plot seems weird Yigit Turgut <y.turgut@gmail.com> - 2011-12-25 10:27 -0800
      Re: Plot seems weird Lie Ryan <lie.1296@gmail.com> - 2011-12-26 20:28 +1100
        Re: Plot seems weird Yigit Turgut <y.turgut@gmail.com> - 2011-12-26 09:08 -0800
          Re: Plot seems weird Lie Ryan <lie.1296@gmail.com> - 2011-12-27 05:58 +1100
            Re: Plot seems weird Yigit Turgut <y.turgut@gmail.com> - 2011-12-26 11:14 -0800
              Re: Plot seems weird Lie Ryan <lie.1296@gmail.com> - 2011-12-27 21:54 +1100

csiph-web