I need help with graphs in python (

Discussion in 'Python' started by hevymetl07, Dec 18, 2012.

  1. hevymetl07

    hevymetl07 Guest

    Hi there, I hope that there is someone willing to help me out, I need to generate a graph in Python, but I am not that skilled with Python and I am completely stuck :(

    I had to make a .CSV file from my Windows system logs (already did that), and the following steps must bw written in the form of a Python script.

    These are some steps I need to do first before creating the graph:
    - Get the name of a CSV file from an ini file,
    - Next, read a line from this CSV file,
    - Increase a variable depending on the Log level (information, warning, error, critical),
    - Read the next line,
    - Then I need to print these results in a Graph.

    I really hope that there is someone there to help me out, and many thanks in advance for all your help!
    hevymetl07, Dec 18, 2012
    1. Advertisements

  2. hevymetl07

    Thomas Bach Guest


    Most of the tasks you have to do can be achieved quite easily with the
    standard library (except the plotting).

    Have a look at the ConfigParser module[1],
    well, the csv module[2] apparently is a good choice for that,
    you maybe want to use collections.counter for that[3]. Anyways, I
    think matplotlib can handle the counting for you…
    this is just iteration over the csv instance you created with your file
    I use matplotlib for this purpose, have a look at their gallery[4] to
    decide what kind of plot best fits your needs.

    I'd recommend to install ipython and start playing around with the
    modules I just told you. If you are stuck somewhere read the
    documentation properly (it's actually all in there) and come back
    again if you cannot come up with a solution.

    Hope this helps,
    Thomas Bach.

    [1] http://docs.python.org/2/library/configparser.html

    [2] http://docs.python.org/2/library/csv.html

    [3] http://docs.python.org/2/library/collections.html#collections.Counter

    [4] http://matplotlib.org/gallery.html
    Thomas Bach, Dec 18, 2012
    1. Advertisements

  3. hevymetl07

    Terry Reedy Guest

    There is only 2.7.3, no, at least not officially.
    It sounds like your data consist of 4 counts. If so, you can easily make
    a simple bar plot with characters

    Log level Number Plot (x = 10)
    ---------- ------ -----------------------------------------------------
    infomation 386 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    warning 97 xxxxxxxxxx
    error 5 x
    critical 23 xxx

    The main problem is to compute the scaling factor from the data.
    You also have to decide on the rounding (I rounded up).
    Terry Reedy, Dec 18, 2012
  4. Since it sounds like the output is going to be a bar-chart, even
    that could be done with the standard library... Based on the counts,
    set the highest count to map to, say 60 (characters), scale the other
    counts proportionately, then generate a display of (use fixed pitch)

    info | ********************
    warn | *****************************************
    error | *******
    crit | **************
    Dennis Lee Bieber, Dec 18, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.