I have a series of files output from another code that contains pre-binned data which I would like to plot up using matplotlib.
A simple example of the contents from one of these files would be:
hist_file=[ 0.00000000e+00, 1.52915100e+24, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 2.03886800e+24, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 5.09717100e+23, 0.00000000e+00,
1.00000000e+00]
Where hist_file[0]
is a reference to the corresponding dump time in the simulation of the data, hist_file[-2]
is the lower bound of the entire data and hist_file[-1]
the upper bound. (so in this set of data, the dump is at 0, the lower bound on the data set is 0, and the upper bound is 1). hist_file[1:-2]
is the binned data I am attempting to visualise.
Using bar
I can plot the data (see code chunk below):
import matplotlib.pyplot as plt
hist_data=hist_file[1:-2]
plt.bar(range(0,len(hist_data)), hist_data)
However, the xticks do not correspond to the actual bin values of the data (the interval [0,1]). This is shown in the following figure
What I thought would work would be something as follows:
import numpy as np
hist_interval=np.linspace(hist_file[-2], hist_file[-1],len(hist_data))
plt.bar(hist_interval, hist_data)
But this produces a bar plot like the following which is clearly not right.
Furthermore I am aware that while I have len(hist_data)
bins, the bin edges would be len(hist_data)+1
which I have been entirely unable to resolve due to their different sizes. Similarly I've tried using plt.set_xaxisticks
and not made any headway either.
So all in all any help would be great thanks :D