Menu

#211 Cannot get histogram plot to work with in-line function using "reasonable" guess at how

None
unread
nobody
histogram (2)
None
2016-12-08
2016-12-03
Anonymous
No

Using version 5.0 patch level 1.0.

I'm trying to get a histogram of an In-line function, but cannot get it to work. Instead, gnuplot does strange stuff. Maybe I'm using it wrong, it seems you must put the data into a file first.

For example, I did this in a cygwin window (simple Bates distribution with n=3, for 20000 samples):
perl -e 'for(1..20000){print ((rand()+rand()+rand())/3.0,"\n")}' > data.txt

Well, okay, actually I needed to use "\r\n" instead of "\n" on Windows. Whatever. Then, in gnuplot:

minx=0.15; maxx=0.85; nsamp=20000.0; nbin=100.0; bin(v)=(v<minx?minx-(maxx-minx)*1.5/nbin:v>maxx?maxx+(maxx-minx)*1.5/nbin:int((v-minx)*(maxx-minx)*nbin+0.5)/nbin/(maxx-minx)+minx); set autoscale xy; \
plot [minx-3*(maxx-minx)/nbin:maxx+3*(maxx-minx)/nbin] "data.txt" using (bin($1)):(1.0/nsamp) smooth frequency with boxes

It gave me exactly the sort of plot I want. But I don't want to have to put the data into a file, especially when all I need to do is check a random distribution. I want to specify the function inline.

But if I try to do the same thing with an in-line function, it simply will not work correctly. Given that the "frequency" style requires x values to count and y values to weigh them with, you would think that going parametric would be required. It sounds reasonable -- let t vary over 20000 samples, but compute each x as the random value (into a bin as before) and let y just be the per-sample weighting (as before). So I've tried that:

minx=0.15; maxx=0.85; nsamp=20000.0; nbin=100.0; bin(v)=(v<minx?minx-(maxx-minx)*1.5/nbin:v>maxx?maxx+(maxx-minx)*1.5/nbin:int((v-minx)*(maxx-minx)*nbin+0.5)/nbin/(maxx-minx)+minx); set autoscale xy; set isosamples nsamp; set parametric; \
plot [minx-3(maxx-minx)/nbin:maxx+3(maxx-minx)/nbin] (bin( (rand(0)+rand(0)+rand(0))/3.0 )),(1.0/nsamp) smooth frequency with boxes

This only shows which x values showed up at all, and not how many times. That is, each box had the same 1.0/nsamp top value, not the count of how many x values fell into that bin. Seems like a defect to me.

It also issues a warning that does not make sense, given that it has boxes for any bin where an x value occurred, which should be stretching vertically from 0 up to 0.00050 along the y axis, but it instead thinks they have no vertical height and tries to spread them across a minuscule range:
Warning: empty y range [5e-005:5e-005], adjusting to [4.95e-005:5.05e-005]

What's up with that?

Discussion

  • Ethan Merritt

    Ethan Merritt - 2016-12-03

    Too complicated for me to follow.
    Can you reduce this to a simpler demonstration?

    Anyhow regardless of anything else I don't think isosamples=20000 will ever be reasonable, and I seriously doubt that "set parametric" is compatible with any of your other plot options. That's just not what it's for.

     
  • Ethan Merritt

    Ethan Merritt - 2016-12-08

    Ticket moved from /p/gnuplot/bugs/1878/

    Can't be converted:

    • _milestone:
    • _priority:
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.