Plotting histograms, scatter plots in Python

Discussion in 'Python' started by Dr. Colombes, Aug 6, 2004.

  1. Dr. Colombes

    Dr. Colombes Guest

    What is the easiest way to generate some plots and graphs in Python ?

    Specifically interested in simple histograms and scatter plots with
    circles and regression lines.

    Thanks for your suggestions.
     
    Dr. Colombes, Aug 6, 2004
    #1
    1. Advertising

  2. Dr. Colombes wrote:

    > What is the easiest way to generate some plots and graphs in Python ?
    >
    > Specifically interested in simple histograms and scatter plots with
    > circles and regression lines.


    google('matplotlib')
    google('gnuplot.py')

    hth,

    f
     
    Fernando Perez, Aug 6, 2004
    #2
    1. Advertising

  3. One module is Matplotlib, that seems to model the Matlab way of doing
    things .... its at sourceforge.

    Peter W.

    At 02:18 PM 8/6/2004, Dr. Colombes wrote:
    >What is the easiest way to generate some plots and graphs in Python ?
    >
    >Specifically interested in simple histograms and scatter plots with
    >circles and regression lines.
    >
    >Thanks for your suggestions.
    >--
    >http://mail.python.org/mailman/listinfo/python-list
     
    Peter Wilkinson, Aug 6, 2004
    #3
  4. Dr. Colombes

    John Hunter Guest

    >>>>> "Colombes" == Colombes <> writes:

    Colombes> What is the easiest way to generate some plots and
    Colombes> graphs in Python ? Specifically interested in simple
    Colombes> histograms and scatter plots with circles and regression
    Colombes> lines.

    Here's a little example of a histogram and regression plot using
    matplotlib - looks easy enough to me! Output image at
    http://nitace.bsd.uchicago.edu:8080/files/share/demo.png

    from matplotlib.matlab import *

    x = randn(10000) # some gaussian noise

    subplot(211) # a subplot
    hist(x, 100) # make a histogram
    grid(True) # make an axes grid
    ylabel('histogram')

    # now do the regression...
    x = arange(0.0, 2.0, 0.05)
    y = 2+ 3*x + 0.2*randn(len(x)) # y is a linear function of x + nse

    # the bestfit line from polyfit
    m,b = polyfit(x,y,1) # a line is 1st order polynomial...

    # plot the data with blue circles and the best fit with a thick
    # solid black line
    subplot(212)
    plot(x, y, 'bo', x, m*x+b, '-k', linewidth=2)
    ylabel('regression')
    grid(True)

    # save the image to hardcopy
    savefig('demo')
    show()
     
    John Hunter, Aug 6, 2004
    #4
  5. Paramjit Oberoi, Aug 6, 2004
    #5
  6. Colin J. Williams, Aug 7, 2004
    #6
  7. Paramjit Oberoi, Aug 7, 2004
    #7
  8. Colin J. Williams wrote:

    >
    >
    > Paramjit Oberoi wrote:
    >>>What is the easiest way to generate some plots and graphs in Python ?

    >>
    >>
    >> Pychart:
    >> http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/

    >
    > The charts look good, but the source code links fail.


    I found it funny that the author makes a comment about poor PostScript quality
    in Gnuplot, touting his as an alternative. If the examples on that page are to
    be believed, that stuff looks like low-quality Excel-type business charts,
    while Gnuplot has been producing publication quality EPS for a loooong time
    (ask the many thousands of scientists using it since the early 90's).

    I'd say that matplotlib is the _real_ contender to gnuplot today, not that toy
    with horrible font scaling, no apparent real symbol/math support, ugly legend
    boxes...

    Best,

    f
     
    Fernando Perez, Aug 8, 2004
    #8
  9. Dr. Colombes

    Guest

    , Aug 9, 2004
    #9
  10. Dr. Colombes

    Dr. Colombes Guest

    John, Peter et al:

    Thanks very much for your useful tips on MathPlotLib.

    I've begun using MatPlotLib and I like it.

    Others suggested GnuPlot, which I hope to try sometime in the
    future.

    Thanks all. This is a good example of very useful information
    exchanged over an Internet newsgroup.

    Dr. Colombes

    John Hunter <> wrote in message news:<>...
    > >>>>> "Colombes" == Colombes <> writes:

    >
    > Colombes> What is the easiest way to generate some plots and
    > Colombes> graphs in Python ? Specifically interested in simple
    > Colombes> histograms and scatter plots with circles and regression
    > Colombes> lines.
    >
    > Here's a little example of a histogram and regression plot using
    > matplotlib - looks easy enough to me! Output image at
    > http://nitace.bsd.uchicago.edu:8080/files/share/demo.png
    >
    > from matplotlib.matlab import *
    >
    > x = randn(10000) # some gaussian noise
    >
    > subplot(211) # a subplot
    > hist(x, 100) # make a histogram
    > grid(True) # make an axes grid
    > ylabel('histogram')
    >
    > # now do the regression...
    > x = arange(0.0, 2.0, 0.05)
    > y = 2+ 3*x + 0.2*randn(len(x)) # y is a linear function of x + nse
    >
    > # the bestfit line from polyfit
    > m,b = polyfit(x,y,1) # a line is 1st order polynomial...
    >
    > # plot the data with blue circles and the best fit with a thick
    > # solid black line
    > subplot(212)
    > plot(x, y, 'bo', x, m*x+b, '-k', linewidth=2)
    > ylabel('regression')
    > grid(True)
    >
    > # save the image to hardcopy
    > savefig('demo')
    > show()
     
    Dr. Colombes, Aug 10, 2004
    #10
  11. Dr. Colombes

    VParekh

    Joined:
    Dec 18, 2009
    Messages:
    1
    Hi

    I have plotted Histogram using plplot. Now I want to calculate each(or which) data point falling into each bin of the histogram. How can I do it?

    Thanks

    ~VParekh
     
    VParekh, Dec 18, 2009
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rhmd
    Replies:
    9
    Views:
    708
    Pat Bills
    Oct 27, 2003
  2. Plotting Histograms

    , Nov 27, 2006, in forum: Java
    Replies:
    2
    Views:
    437
    Andrew Thompson
    Nov 27, 2006
  3. Plotting histograms

    , Oct 17, 2006, in forum: Python
    Replies:
    14
    Views:
    1,244
    Robert Kern
    Oct 19, 2006
  4. Roedy Green

    histograms

    Roedy Green, Aug 7, 2008, in forum: Java
    Replies:
    3
    Views:
    484
    Arne Vajhøj
    Aug 9, 2008
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    673
    C Barrington-Leigh
    Sep 12, 2010
Loading...

Share This Page