Reputation: 143
I'm new to Julia and know some about it but I was recently asked to create a histogram out of two 70-element array float elements, so, for example:
I have two lists of elements, say:
x = [1.3, 4.6, 7.8, 10.4, 200.4, 1000.42, 1111.1, 1234.56]
y = [0, 0, 3, 2, 0, 7, 32, 0]
How can I make a Histogram out of this?
Upvotes: 1
Views: 1122
Reputation: 42234
You can use PyPlot for this (please not that it should be installed first)
using PyPlot
PyPlot.plt[:hist]([x,y],bins=8);
Michel's comment below is right - you did not explain what is the data and it does not seem like typical data for histogram.
If x
holds bar location and y
bar heights you could do
p = PyPlot.plt[:bar](x,y,width=25);
Yet another option (this will show x
values as bar labels:
PyPlot.plt[:cla]() #remember to clear the plot :-)
PyPlot.plt[:bar](1:length(y),y);
PyPlot.plt[:xticks](1:length(y),x);
Upvotes: 2
Reputation: 8044
Those variables, by the look of it, don't look like something you'd run histogram
on. They look like the bin centers of the histogram, and the count of data points in each. As such, it essentially already might be a histogram.
If you want to plot a histogram from edges and counts, you'd use a bar
plot (not a histogram
plot, which involves binning your data into a histogram and plotting it).
But, your variables are not evenly spaced, and y
are not floats, though you write they are. Are these the correct numbers?
Upvotes: 1