A Simple Example of histogram Using Range?

See Subject. I don't seem able to produce a simple example of using histogram that uses range. I tried a variety of ranges, range=(0,22), range=(0, 50.2), ... and I see no difference between any of the x values scale. Can someone provide an example that shows how it works?

···

--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site: 39� 15' 7" N, 121� 2' 32" W, 2700 feet
                                   350 350 350 350 350 350 350 350 350 350
                     Make the number famous. See 350.org
            The major event has passed, but keep the number alive.
                     Web Page: <www.speckledwithstars.net/>

Wayne Watson skrev:

See Subject. I don't seem able to produce a simple example of using histogram that uses range. I tried a variety of ranges, range=(0,22), range=(0, 50.2), ... and I see no difference between any of the x values scale. Can someone provide an example that shows how it works?

The script below works for me. It produces two files with different limits on the x-axis and corresponding histograms.

···

------------
import matplotlib.pyplot as plt

fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 20))
plt.savefig("hist_0_20.png")
plt.close(fig)

fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 8))
plt.savefig("hist_0_8.png")
plt.close(fig)
-------------

Hope it helps

/ johan

Hi, this is an odd result. I copied your code and tried to execute it
with Python 2.5. It came back with a socket area, and a reference to my
firewall. Very strange. Ah, I happen to have a comm port open to another
computer. Apparently Python didn't like that.

Anyway, where, folder, does your program write the files? I'm not
familiar with figure, but apparently using it produces some "canvas"
that plt.hist places it's output on. One can than save fig to a file.
What happens if I don't use figure? I just put a copy of the line
plt.hist([1, 2, 3, 4, 5], range=(0, 20)) after import. When I execute
the program, I don't see a graphic appear. So doesn't matplotlib produce
graphic output aside from use of figure?

I think I've confused hist as part of numpy and histogram as part of
matplotlib. A visit to the numpy and matplotlib web sites shows I am
confused.

Let's see. I want to know how to use a histogram in Python, so there is
a histogram function and a hist. So a histogram is for histograms. What
fun word play. :slight_smile: Maybe numpy should have called their function ahistogram!

Johan Gr�nqvist wrote:

···

Wayne Watson skrev:
  

See Subject. I don't seem able to produce a simple example of using histogram that uses range. I tried a variety of ranges, range=(0,22), range=(0, 50.2), ... and I see no difference between any of the x values scale. Can someone provide an example that shows how it works?

The script below works for me. It produces two files with different limits on the x-axis and corresponding histograms.

------------
import matplotlib.pyplot as plt

fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 20))
plt.savefig("hist_0_20.png")
plt.close(fig)

fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 8))
plt.savefig("hist_0_8.png")
plt.close(fig)
-------------

Hope it helps

/ johan

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site: 39� 15' 7" N, 121� 2' 32" W, 2700 feet

                   350 350 350 350 350 350 350 350 350 350
                     Make the number famous. See 350.org
            The major event has passed, but keep the number alive.

                    Web Page: <www.speckledwithstars.net/>

Wayne Watson skrev:

Anyway, where, folder, does your program write the files? I'm not
familiar with figure, but apparently using it produces some "canvas"
that plt.hist places it's output on. One can than save fig to a file.
What happens if I don't use figure? I just put a copy of the line
plt.hist([1, 2, 3, 4, 5], range=(0, 20)) after import. When I execute
the program, I don't see a graphic appear. So doesn't matplotlib produce
graphic output aside from use of figure?

My intuition is exactly like that.

After importing matplotlib.pyplt as plt, plt.figure creates an object that acts as canvas, and then I plot various things (hist, is one example), and when I am satisfied, I plt.savefig(path) or plt.show() the figure. The figures are saved in the directory where the script is run (its cwd, or current working directory, on linux).

I have also used hist without having a figure, but that was because I wanted the histogram data, i.e., the numbers of data points in the different bins. That script used plt.hist to generate such data, and later (after running fig = plt.figure) used plt.plot to plot parts of the data in different ways.

By the way, matplotlib.pyplot is one way of using matplotlib. There is also the "object oriented interface", which I have never used.

/ johan

I'm on Win XP, and have no idea where the images went. I guess I'll have
to search my C-disk. I just began the search.

Looking at C:\Python25, I see no image files. Same with C:\Python25\Scripts

If I put some code up front as below, the image comes up on my screen,
but using a range of 0 to 8 and 0, 18 changes nothing. Further the
program hangs up.

So far matplotlib pretty much leaves the user on his own. Yes, there are
plenty of examples, but there seem to be no explanations about matters
like figure or show. No tutor on any of this I guess. Apparently, they
are leaving it up to one's MATLAB experience. It's been quite awhile
since I used that. It still resides on my computer.

Ah, the png files were found in the folder where the program is located.
I can clearly see the changes from your switches between range values.

=================inserted a few lines at the top and some print debug
stmts=====
import matplotlib.pyplot as plt
print "let's start the histogram"
plt.hist([1, 2, 3, 4, 5], range=(0, 18))
plt.show()
#raw_input("Hey")
fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 20))
plt.show()
plt.savefig("hist_0_20.png")
plt.close(fig)

fig = plt.figure()
plt.hist([1, 2, 3, 4, 5], range=(0, 8))
plt.savefig("hist_0_8.png")
plt.close(fig)
print "finished"

Johan Gr�nqvist wrote:

···

Wayne Watson skrev:
  

Anyway, where, folder, does your program write the files? I'm not
familiar with figure, but apparently using it produces some "canvas"
that plt.hist places it's output on. One can than save fig to a file.
What happens if I don't use figure? I just put a copy of the line
plt.hist([1, 2, 3, 4, 5], range=(0, 20)) after import. When I execute
the program, I don't see a graphic appear. So doesn't matplotlib produce
graphic output aside from use of figure?

My intuition is exactly like that.

After importing matplotlib.pyplt as plt, plt.figure creates an object that acts as canvas, and then I plot various things (hist, is one example), and when I am satisfied, I plt.savefig(path) or plt.show() the figure. The figures are saved in the directory where the script is run (its cwd, or current working directory, on linux).

I have also used hist without having a figure, but that was because I wanted the histogram data, i.e., the numbers of data points in the different bins. That script used plt.hist to generate such data, and later (after running fig = plt.figure) used plt.plot to plot parts of the data in different ways.

By the way, matplotlib.pyplot is one way of using matplotlib. There is also the "object oriented interface", which I have never used.

/ johan

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site: 39� 15' 7" N, 121� 2' 32" W, 2700 feet

                   350 350 350 350 350 350 350 350 350 350
                     Make the number famous. See 350.org
            The major event has passed, but keep the number alive.

                    Web Page: <www.speckledwithstars.net/>

Wayne Watson skrev:

So far matplotlib pretty much leaves the user on his own. Yes, there are
plenty of examples, but there seem to be no explanations about matters
like figure or show. No tutor on any of this I guess. Apparently, they
are leaving it up to one's MATLAB experience. It's been quite awhile
since I used that. It still resides on my computer.

I have mostly used my experience from matlab and other graphics packages, along with the examples and documentation available on the webpage, but there is now also a book about matplotlib.

http://sandrotosi.blogspot.com/2009/11/matplotlib-for-python-developers.html

/ johan