need some advice on x y plot

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nephish@xit.net

    #1

    need some advice on x y plot

    Hey there,
    i have tried about every graphing package for python i can get to work
    on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get
    matplot to work)
    so far, they all are working ok. I need to make an x y chart for some
    data that comes in from sensors at different times durring the day. i
    need it to show the value in the y and the time in the x . no problem
    so far. But what i cannot get to happen is to scale x (time of the
    plot) with respect to time. in other words, i get a chart with the
    times evenly spaced out along the x axis, with their respective values.
    i need the chart to show gaps when there are gaps in the data. i need
    it to be able to scale by time. if i have 3 values that come in within
    a few minutes, i need them to be displayed close together, as compared
    to another value that may come in, say, an hour later. Does this make
    sence ?
    one of you guys know a charting app that will do this ? or is there
    some other way i could do it?

    looking for suggestions,
    sk

  • Grant Edwards

    #2
    Re: need some advice on x y plot

    On 2005-10-20, nephish@xit.net <nephish@xit.ne t> wrote:
    [color=blue]
    > [...] I need to make an x y chart for some data that comes in
    > from sensors at different times durring the day. i need it to
    > show the value in the y and the time in the x . no problem so
    > far. But what i cannot get to happen is to scale x (time of
    > the plot) with respect to time.[/color]

    Gnuplot does that just fine. Just give it two columns of data, the
    first being the x value (time) and the second being the y value.

    All of the other plotting packages handle this as well.

    --
    Grant Edwards grante Yow! I hope I
    at bought the right
    visi.com relish... zzzzzzzzz...

    Comment

    • nephish@xit.net

      #3
      Re: need some advice on x y plot

      how ?
      i have tried to use unix timestamps, and i have also tried with
      DateTime objects
      do i need to use a scale that isn't linear (default in most) ?
      how do i putt this off ?

      thanks btw.
      sk

      Comment

      • Larry Bates

        #4
        Re: need some advice on x y plot

        I would try to live with time scale being fixed and insert
        None (or whatever value is used by charting package) for
        times where observations were not taken. This will mean that
        you have to preprocess your data by determining a time step
        step value that will fit your data. If you get 3 observations
        each 10 minutes apart then one an hour later, you will need to
        insert 5 empty observations in the list before the last
        observation.

        Example:

        1:00 <value1>
        1:10 <value2>
        1:20 <value3>
        2:20 <value4>

        1:00 <value1>
        1:10 <value2>
        1:20 <value3>
        1:30 <empty value>
        1:40 <empty value>
        1:50 <empty value>
        2:00 <empty value>
        2:10 <empty value>
        2:20 <value4>

        Maybe this will be of some help and I'm sure there are other ways.

        -Larry

        nephish@xit.net wrote:[color=blue]
        > Hey there,
        > i have tried about every graphing package for python i can get to work
        > on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get
        > matplot to work)
        > so far, they all are working ok. I need to make an x y chart for some
        > data that comes in from sensors at different times durring the day. i
        > need it to show the value in the y and the time in the x . no problem
        > so far. But what i cannot get to happen is to scale x (time of the
        > plot) with respect to time. in other words, i get a chart with the
        > times evenly spaced out along the x axis, with their respective values.
        > i need the chart to show gaps when there are gaps in the data. i need
        > it to be able to scale by time. if i have 3 values that come in within
        > a few minutes, i need them to be displayed close together, as compared
        > to another value that may come in, say, an hour later. Does this make
        > sence ?
        > one of you guys know a charting app that will do this ? or is there
        > some other way i could do it?
        >
        > looking for suggestions,
        > sk
        >[/color]

        Comment

        • nephish@xit.net

          #5
          Re: need some advice on x y plot

          i have thought about doing this, just a little different. i was going
          to list the value pairs.
          take the start time and end time and plot 100 empty plots between them.
          add the value pairs, sort by time, and then draw it. The only thing is
          it get kinda complicated when the times change a lot. they could span
          an hour, a month, anything in between.

          i like your idea, i will check various packages for how to plot 'none'

          thanks
          sk.

          Comment

          • Grant Edwards

            #6
            Re: need some advice on x y plot

            On 2005-10-20, nephish@xit.net <nephish@xit.ne t> wrote:
            [color=blue]
            > i have tried to use unix timestamps,[/color]

            That has always worked for me. What happened?
            [color=blue]
            > and i have also tried with DateTime objects[/color]

            Never tried that.
            [color=blue]
            > do i need to use a scale that isn't linear (default in most) ?[/color]

            No.
            [color=blue]
            > how do i putt this off ?[/color]

            Huh?

            Gnuplot by default does exactly what you seem to want if you
            just pass it x,y values.

            --
            Grant Edwards grante Yow! I always liked FLAG
            at DAY!!
            visi.com

            Comment

            • Grant Edwards

              #7
              Re: need some advice on x y plot

              On 2005-10-20, Larry Bates <larry.bates@we bsafe.com> wrote:
              [color=blue]
              > I would try to live with time scale being fixed[/color]

              I don't understand what you mean by "the time scale being
              fixed". It's not. If you just pass the time,value pairs to
              gnuplot, it does exactly what it should.
              [color=blue]
              > and insert
              > None (or whatever value is used by charting package) for
              > times where observations were not taken. This will mean that
              > you have to preprocess your data by determining a time step
              > step value that will fit your data. If you get 3 observations
              > each 10 minutes apart then one an hour later, you will need to
              > insert 5 empty observations in the list before the last
              > observation.
              >
              > Example:
              >
              > 1:00 <value1>
              > 1:10 <value2>
              > 1:20 <value3>
              > 2:20 <value4>
              >
              > 1:00 <value1>
              > 1:10 <value2>
              > 1:20 <value3>
              > 1:30 <empty value>
              > 1:40 <empty value>
              > 1:50 <empty value>
              > 2:00 <empty value>
              > 2:10 <empty value>
              > 2:20 <value4>[/color]

              That's completely unnecessary. Just pass a set of time,value
              pairs and they'll get plotted as desired.

              --
              Grant Edwards grante Yow! As a FAD follower,
              at my BEVERAGE choices are
              visi.com rich and fulfilling!

              Comment

              • Grant Edwards

                #8
                Re: need some advice on x y plot

                On 2005-10-20, Grant Edwards <grante@visi.co m> wrote:
                [color=blue][color=green]
                >> and insert None (or whatever value is used by charting
                >> package) for times where observations were not taken. This
                >> will mean that you have to preprocess your data by determining
                >> a time step step value that will fit your data. If you get 3
                >> observations each 10 minutes apart then one an hour later, you
                >> will need to insert 5 empty observations in the list before
                >> the last observation.[/color][/color]
                [...][color=blue]
                >
                > That's completely unnecessary. Just pass a set of time,value
                > pairs and they'll get plotted as desired.[/color]

                For example, here's how gnuplot plots the data

                2 12
                3 10
                4 9
                101 8
                102 6
                103 9



                20 ++----------+-----------+-----------+----------+-----------+----------++
                + + + + + "foo.dat" A +
                | |
                | |
                | |
                15 ++ ++
                | |
                | |
                |A |
                | |
                10 ++A ++
                | A A |
                | A |
                | |
                | A |
                5 ++ ++
                | |
                | |
                | |
                + + + + + + +
                0 ++----------+-----------+-----------+----------+-----------+----------++
                0 20 40 60 80 100 120


                Isn't that what you're asking for?

                --
                Grant Edwards grante Yow! ... I have read the
                at INSTRUCTIONS...
                visi.com

                Comment

                • Kent Johnson

                  #9
                  Re: need some advice on x y plot

                  nephish@xit.net wrote:[color=blue]
                  > how ?
                  > i have tried to use unix timestamps, and i have also tried with
                  > DateTime objects
                  > do i need to use a scale that isn't linear (default in most) ?
                  > how do i putt this off ?[/color]

                  Here is some code that works for me. It plots multiple datasets against time. The input data looks like this:
                  2005-04-04 16:00:00 141.154.195.129 - W3SVC1 SP6018ASP2 208.254.37.191 443 GET /rkadqsr/newskills/newskills.cfm selectedTab=1 200 0 53440 599 1594 HTTP/1.1 adqsr.skillport .com Mozilla/4.0+(compatible ;+MSIE+6.0;+Win dows+NT+5.1) CookiesEnabled= 1;+ASPSESSIONID ACTSSRAT=MCNLNL GADPOFGFKAHJHLD DKG;+CFID=78503 0;+CFTOKEN=2720 3160 https://adqsr.skillport.com/rkadqsr/login/login.cfm
                  2005-04-04 16:00:00 208.254.38.216 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend _od_cgi/aiccisapi.dll - 200 0 372 274 4547 HTTP/1.0 adqsr.skillport .com aiccisapi - -
                  2005-04-04 16:00:00 208.254.38.240 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend _od_cgi/aiccisapi.dll - 200 0 372 3019 250 HTTP/1.0 adqsr.skillport .com aiccisapi - -

                  import datetime, time
                  import Gnuplot

                  dataPath = 'ex05040416.log '

                  datasets = {}
                  startTime = None

                  f = open(dataPath)

                  for line in f:
                  try:
                  dat, tim, c_ip, cs_username, s_sitename, s_computername, s_ip, s_port, \
                  cs_method, cs_uri_stem, cs_uri_query, sc_status, sc_win32_status , sc_bytes, \
                  cs_bytes, time_taken, cs_version, cs_host, cs_User_Agent, cs_Cookie, cs_Referer = line.split()
                  except ValueError:
                  print "Can't parse", line
                  continue

                  tim = time.mktime(tim e.strptime(dat+ ' '+tim, "%Y-%m-%d %H:%M:%S"))
                  delay = int(time_taken)

                  if startTime is None:
                  startTime = tim

                  tim -= startTime

                  # print tim, delay
                  datasets.setdef ault(sc_status, []).append([tim, delay])

                  g = Gnuplot.Gnuplot (debug=1)

                  plotter = g.plot
                  for key, values in datasets.items( ):
                  plotter(values)
                  plotter = g.replot

                  raw_input('Plea se press return to continue...\n')

                  Comment

                  • nephish@xit.net

                    #10
                    Re: need some advice on x y plot

                    ok, yeah, thats exactly what i am looking for. i will give it a go.
                    thanks a whole lot.

                    putt this off is a typo, pull this off is what i was meaning to type.

                    this is cool.

                    Comment

                    • nephish@xit.net

                      #11
                      Re: need some advice on x y plot

                      ok, i tried something similar to what you posted.
                      a little simpler though.
                      i am running a query on a database and making a list of time, value
                      pairs
                      kinda like this
                      plot_points = ([time, value], [time, value], [time, value])
                      gnuplot complains that it needs a float for one of the values.
                      i can plot just the value, and it shows up ( no x value found)

                      how should i proceed?

                      Comment

                      • Kent Johnson

                        #12
                        Re: need some advice on x y plot

                        nephish@xit.net wrote:[color=blue]
                        > i am running a query on a database and making a list of time, value
                        > pairs
                        > kinda like this
                        > plot_points = ([time, value], [time, value], [time, value])
                        > gnuplot complains that it needs a float for one of the values.
                        > i can plot just the value, and it shows up ( no x value found)
                        >
                        > how should i proceed?[/color]

                        Convert one of the values to a float? What are your time and value numbers?

                        Kent

                        Comment

                        • nephish@xit.net

                          #13
                          Re: need some advice on x y plot

                          the time is DateTime.DateTi me object from a mySQLdb query.
                          the value is a number anywhere between 0 and 15.
                          the datetime is formatted like 2005-10-20 08:40:34

                          i could strip it and make a timestamp out of it. but reading the
                          number of seconds since january of 1970 doesn't make a neat chart.

                          any suggestions?

                          oh, and can you output from Gnuplot to a png or jpeg or something like
                          that.
                          the Gnuplot documentation says that it can make a bitmap png but i dont
                          know how to do that with the python wrapper. the docs for this are a
                          little cryptic.
                          still a newbie here. if you know a good tutorial on this, i would
                          really appreciate the link.

                          thanks for your time, and brain

                          Comment

                          • William Park

                            #14
                            Re: need some advice on x y plot

                            nephish@xit.net wrote:[color=blue]
                            > the time is DateTime.DateTi me object from a mySQLdb query.
                            > the value is a number anywhere between 0 and 15.
                            > the datetime is formatted like 2005-10-20 08:40:34
                            >
                            > i could strip it and make a timestamp out of it. but reading the
                            > number of seconds since january of 1970 doesn't make a neat chart.
                            >
                            > any suggestions?[/color]

                            Python is capable of integer arithmetic, eg.[color=blue][color=green][color=darkred]
                            >>> 2000 - 500[/color][/color][/color]
                            1500

                            --
                            William Park <opengeometry@y ahoo.ca>, Toronto, Canada
                            ThinFlash: Linux thin-client on USB key (flash) drive

                            BashDiff: Super Bash shell
                            Compare the best free open source Software Development Software at SourceForge. Free, secure and fast Software Development Software downloads from the largest Open Source applications and software directory

                            Comment

                            • Grant Edwards

                              #15
                              Re: need some advice on x y plot

                              On 2005-10-21, nephish@xit.net <nephish@xit.ne t> wrote:
                              [color=blue]
                              > the time is DateTime.DateTi me object from a mySQLdb query. the
                              > value is a number anywhere between 0 and 15. the datetime is
                              > formatted like 2005-10-20 08:40:34
                              >
                              > i could strip it and make a timestamp out of it. but reading
                              > the number of seconds since january of 1970 doesn't make a
                              > neat chart.[/color]

                              Pass the data values as floating point numbers (I typically use
                              seconds since the test run started). If you the x tics to be
                              something else, then change them. It's pretty simple to label
                              the x-axis using normal date/time notation.
                              [color=blue]
                              > any suggestions?
                              >
                              > oh, and can you output from Gnuplot to a png or jpeg or
                              > something like that.[/color]

                              Is that a question? If so, the answer is yes.
                              [color=blue]
                              > the Gnuplot documentation says that it can make a bitmap png
                              > but i dont know how to do that with the python wrapper. the
                              > docs for this are a little cryptic. still a newbie here. if
                              > you know a good tutorial on this, i would really appreciate
                              > the link.[/color]

                              Once you start doing "odd" stuff (e.g. custom labels for the x-axis,
                              output other than X11 or postscript), it's usually simplest to
                              just send normal gnuplot commands.

                              ------------------------------8<------------------------------
                              import Gnuplot,time,sy s,math

                              def pause():
                              sys.stdout.writ e("Press enter to continue: ")
                              sys.stdin.readl ine()

                              def fgrid(start,sto p,count):
                              for i in xrange(count):
                              yield start + ((stop-start)*i)/count

                              start = time.time()

                              xdata = [x for x in fgrid(0,600.0,1 0)] # two minutes worth
                              ydata = [math.sin(x/100.0) for x in xdata]

                              data = Gnuplot.Data(xd ata,ydata,with= 'linespoints')

                              gp = Gnuplot.Gnuplot ()
                              gp.title('Data starting at %s' % time.ctime(star t+xdata[0]))

                              # x axis will use default tics (seconds since start of run)
                              gp.plot(data)
                              pause()

                              # now let's change x tics to time of day in HH:MM:SS with
                              # ticmarks at 120 second intervals

                              ti = 120.0
                              startTic = int((start+xdat a[0])//ti * ti)
                              endTic = int((start+xdat a[-1])//ti * ti)
                              ti = int(ti)

                              ticx = range(startTic, endTic+ti,ti)
                              tics = [(x, time.strftime(' %H:%M:%S',time. localtime(x))) for x in ticx]
                              ticstrings = ['"%s" %f' % (t[1],t[0]-start) for t in tics]

                              gp('set xtics (%s)' % ','.join(ticstr ings))
                              gp.plot(data)
                              pause()

                              outfile = 'foo.png'
                              gp('set term png')
                              gp('set out "%s"' % outfile)
                              gp.plot(data)
                              ------------------------------8<------------------------------

                              --
                              Grant Edwards grante Yow! ... The waitress's
                              at UNIFORM sheds TARTAR SAUCE
                              visi.com like an 8" by 10" GLOSSY...

                              Comment

                              Working...