Is there a way I can align the histogram with the function plot in this graph?

Viewed 59

Here's a plot I currently have: (using Python)

enter image description here

The darkorange curve is my function, generated from

plt.plot(x,Yt,color = 'darkorange')

while the histogram comes from

plt.bar(dic.keys(), dic.values(), width=np.abs((rang2-rang1)/N), color='lightcoral') 

From this graph we can see they are not quite aligned at the bottom (where both of them should be 0), I'm wondering is there a way I can make them aligned? Thanks!!

1 Answers

you might need to play around with the offset number below

offset = 0.01


Yt = [y-offset for y in Yt]

plt.plot(x,Yt,color = 'darkorange')

note that if you want to only offset outside the peak range of the function (the spiky part in the middle) you would need a non-constant offset.

Related