I am plotting a bar chart and some values dont match the numbers in the code:
import numpy as np import matplotlib.pyplot as plt height_list = [0.001, 0.000464, 0.000464, 0.000215, 0.000215, 0.000215, 0.0001, 0.0001] bottom_list = [2.15e-07, 2.15e-07, 4.64e-07, 4.64e-07, 1e-06, 1e-05, 4.64e-05, 9.5e-05] plot = plt.bar(x=np.arange(5, 41, 5), height=height_list, width=2, bottom=bottom_list) plt.yscale('log') plt.show()
Here is the resulting plot. According to the input, the third to last bar should align with the green line and the top ends of the last two bars should align with the red line. The other bars are displayed correctly. What causes this discrepancy?
Here is the same plot alongside a bar plot with the same height values but without any bottom values. In this one, all values are displayed correctly.
The plot is right.
plt.bar plots a bar from the
bottom, with a certain
height, that means that the top of your plots are at bottom + height.
What is misleading you is that, for the first bars (on the left), the bottom is so low that it does not reflect on the top, hence we have top ~ height.
bottom_list = [2.15e-07, 2.15e-07, 4.64e-07, 4.64e-07, 4.64e-07, 4.64e-07, 4.64e-05, 4.64e-05]