Discussion:
[Matplotlib-users] A request for a Matplotlib extension to hist
Virgil Stokes
2015-04-24 10:33:59 UTC
Permalink
I have some Python (2.7.9) code that processes some rather large data sets to
determine the curvatures along 2D curves. One feature of these data that I like
to look at is the distribution of the curvatures. I use NumPy to to determine
histograms for each set, and save the histogram parameters returned from
numpy.histogram in a file.

I would like to use Matplotlib to plot histograms *from the parameters returned
in NumPy* and stored in a file --- why? Because the size of my data sets does
not allow for the use of the histogram plot function in Matplotlib (1.4.3);
i.e., it needs the data sets to calculate the histogram, before doing the plot.
I would like to have a histogram plot function in Matplotlib that could bypass
the actual calculation of the bin counts and edges from the data, and use values
of these found /a priori/. Of course, an obvious question is -- Why not write
code to plot the rectangles yourself? Yes, I could do this; but, why not extend
the Matplotlib histogram class to allow for this option? If I better understood
Matplotlib, I would try this myself. Maybe it is possible to get this into the
next planned release (1.5).:-)

If this request is inappropriate for this list, then please accept my apology
and direct me to where I should send this request.

Best regards.
Christian Alis
2015-04-24 10:58:37 UTC
Permalink
I had the same problem some time ago and what I did is to use bar() to
plot the histogram, which can be done in one line:

hist, bin_edges = np.histogram(data)
plt.bar(bin_edges[:-1], hist)

Perhaps this trick can be added in the documentation?

I am willing to code Virgil's request if many will find this useful.
Post by Virgil Stokes
I have some Python (2.7.9) code that processes some rather large data sets
to determine the curvatures along 2D curves. One feature of these data that
I like to look at is the distribution of the curvatures. I use NumPy to to
determine histograms for each set, and save the histogram parameters
returned from numpy.histogram in a file.
I would like to use Matplotlib to plot histograms from the parameters
returned in NumPy and stored in a file --- why? Because the size of my data
sets does not allow for the use of the histogram plot function in Matplotlib
(1.4.3); i.e., it needs the data sets to calculate the histogram, before
doing the plot. I would like to have a histogram plot function in Matplotlib
that could bypass the actual calculation of the bin counts and edges from
the data, and use values of these found a priori. Of course, an obvious
question is -- Why not write code to plot the rectangles yourself? Yes, I
could do this; but, why not extend the Matplotlib histogram class to allow
for this option? If I better understood Matplotlib, I would try this myself.
Maybe it is possible to get this into the next planned release (1.5). :-)
If this request is inappropriate for this list, then please accept my
apology and direct me to where I should send this request.
Best regards.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Virgil Stokes
2015-04-24 11:26:18 UTC
Permalink
Post by Christian Alis
I had the same problem some time ago and what I did is to use bar() to
hist, bin_edges = np.histogram(data)
plt.bar(bin_edges[:-1], hist)
Very elegant Christian :-)
Post by Christian Alis
Perhaps this trick can be added in the documentation?
Well, I vote to add it. However, I did find the following nice example (after
reading your email) that shows how the bar function might be used
(http://matplotlib.org/examples/api/barchart_demo.html) for my problem. Had I
seen this before, I probably would not have posted this request.:-[
Post by Christian Alis
I am willing to code Virgil's request if many will find this useful.
Post by Virgil Stokes
I have some Python (2.7.9) code that processes some rather large data sets
to determine the curvatures along 2D curves. One feature of these data that
I like to look at is the distribution of the curvatures. I use NumPy to to
determine histograms for each set, and save the histogram parameters
returned from numpy.histogram in a file.
I would like to use Matplotlib to plot histograms from the parameters
returned in NumPy and stored in a file --- why? Because the size of my data
sets does not allow for the use of the histogram plot function in Matplotlib
(1.4.3); i.e., it needs the data sets to calculate the histogram, before
doing the plot. I would like to have a histogram plot function in Matplotlib
that could bypass the actual calculation of the bin counts and edges from
the data, and use values of these found a priori. Of course, an obvious
question is -- Why not write code to plot the rectangles yourself? Yes, I
could do this; but, why not extend the Matplotlib histogram class to allow
for this option? If I better understood Matplotlib, I would try this myself.
Maybe it is possible to get this into the next planned release (1.5). :-)
If this request is inappropriate for this list, then please accept my
apology and direct me to where I should send this request.
Best regards.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Keep up the good work on Matplotlib and I look forward to vers. 1.5 :-)
Jerzy Karczmarczuk
2015-04-24 11:31:10 UTC
Permalink
Le 24/04/2015 12:58, Christian Alis responds to the problem posed by
Virgil Stokes
Post by Christian Alis
I had the same problem some time ago and what I did is to use bar() to
hst, bin_edges = np.histogram(data)
plt.bar(bin_edges[:-1], hst)
Perhaps this trick can be added in the documentation?
I am willing to code Virgil's request if many will find this useful.
Separating the computation of the histogram, and plotting it is
obviously useful.
(I needed this in a linguistical simulation context, where plotting had
no sense).

Actually hist is more or less this,
see _axes.py, line 5678, the Axes method hist just calls
numpy.histogram. And then plots bars (or uses some other style).

So, although completing the documentation might be of general interest,
I would NOT recommend adding some new version of hist.
This would be misleading. Hist is hist is hist(ogram). It computes the
histogram (and eventually plots it). If it is already computed elsewhere,
naming the procedure which JUST plots some bars a "histogram" is
methodologically very dubious.

Jerzy Karczmarczuk
Antonino Ingargiola
2015-04-24 18:04:25 UTC
Permalink
Hi,

I think there is a good reason to add the functionality to plot
pre-computed histograms to hist() or to a new function with similar API.

Sometimes histograms are heavy or we don't want to recompute them to
perform a series of plots.

In this case, I miss the ability to easily set the plot style. hist()
allows to chose between bar, step and stepfilled. To change the style with
pre-computed histograms, I need to write 3 different "plots" using bar(),
plot() and fill_between() respectively. This is quite inconvenient and
error prone, considering that these function have different API for the
input data.

Maybe the plotting part of hist() should be splitted in a standalone
function (plotbins() ?)
In this way, hist() can call this function to generate the plot, but also
the user can call it when the histogram is pre-computed. The bonus is that
we retain the same API for plot style.

My 2cents,
Antonio


On Fri, Apr 24, 2015 at 4:31 AM, Jerzy Karczmarczuk <
Post by Jerzy Karczmarczuk
Le 24/04/2015 12:58, Christian Alis responds to the problem posed by
Virgil Stokes
Post by Christian Alis
I had the same problem some time ago and what I did is to use bar() to
hst, bin_edges = np.histogram(data)
plt.bar(bin_edges[:-1], hst)
Perhaps this trick can be added in the documentation?
I am willing to code Virgil's request if many will find this useful.
Separating the computation of the histogram, and plotting it is
obviously useful.
(I needed this in a linguistical simulation context, where plotting had
no sense).
Actually hist is more or less this,
see _axes.py, line 5678, the Axes method hist just calls
numpy.histogram. And then plots bars (or uses some other style).
So, although completing the documentation might be of general interest,
I would NOT recommend adding some new version of hist.
This would be misleading. Hist is hist is hist(ogram). It computes the
histogram (and eventually plots it). If it is already computed elsewhere,
naming the procedure which JUST plots some bars a "histogram" is
methodologically very dubious.
Jerzy Karczmarczuk
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...