0

My barplot looks really odd even though the bars are equally spaced. I've tried changing the value of width as suggested in some questions on the site, but doesn't seem to work.

import matplotlib.pyplot as plt

plt.plot(np.arange(101), y_values)

enter image description here

Data

import numpy as np

y_values = np.array([0.00000000e+00, 4.46017491e-05, 1.78228335e-04, 3.94968306e-04,
       7.05572009e-04, 1.10294612e-03, 1.59572483e-03, 2.17243283e-03,
       2.84177628e-03, 3.60957017e-03, 4.50392136e-03, 5.40575790e-03,
       6.44159603e-03, 7.61335329e-03, 8.78182306e-03, 1.00079004e-02,
       1.15787142e-02, 1.31326426e-02, 1.46676289e-02, 1.61098107e-02,
       1.75799303e-02, 1.93086811e-02, 2.09015849e-02, 2.27009145e-02,
       2.46893667e-02, 2.66487747e-02, 2.89564918e-02, 3.10194030e-02,
       3.25402707e-02, 3.44719217e-02, 3.65677393e-02, 3.86684893e-02,
       4.07881872e-02, 4.27839562e-02, 4.48701416e-02, 4.69774729e-02,
       4.90641141e-02, 5.02142999e-02, 5.17740449e-02, 5.42603311e-02,
       5.61076524e-02, 5.79647124e-02, 5.97311019e-02, 4.60923811e-02,
       4.30526553e-02, 4.40846695e-02, 4.45105083e-02, 4.36330977e-02,
       4.38616968e-02, 4.38591822e-02, 4.36181053e-02, 4.40751652e-02,
       4.39859679e-02, 4.38144938e-02, 4.31526286e-02, 4.28167177e-02,
       4.21498922e-02, 4.16571611e-02, 4.11433349e-02, 4.05672728e-02,
       3.97877714e-02, 3.77570996e-02, 3.70200823e-02, 3.71110631e-02,
       3.62956751e-02, 3.50543928e-02, 3.41830966e-02, 3.32808383e-02,
       3.23516182e-02, 2.69930810e-02, 2.61901459e-02, 2.49559825e-02,
       2.06100523e-02, 1.98932708e-02, 1.91775138e-02, 1.84337186e-02,
       1.77275385e-02, 1.69557754e-02, 1.62744272e-02, 1.53908759e-02,
       1.47288563e-02, 1.40068169e-02, 1.33777826e-02, 1.27589295e-02,
       1.21303283e-02, 1.15382194e-02, 1.09588884e-02, 1.03926769e-02,
       9.79746474e-03, 9.26607406e-03, 8.75044543e-03, 8.25090657e-03,
       7.76813430e-03, 7.30248944e-03, 6.85433170e-03, 6.42385953e-03,
       6.01121947e-03, 5.61647736e-03, 5.23962166e-03, 4.88056729e-03,
       4.53915984e-03])
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Physics_Student
  • 556
  • 2
  • 9
  • 1
    What do you mean "x values are [uniform]"? There is a discontinuity in the progression of your data between 5.97311019e-02 and 4.60923811e-02. Which is seen as expected on the plot. – Tranbi Aug 16 '23 at 13:21
  • The code you provided does not represent any bar plot. Please provide the code you actually used. Also what is it you find odd about your plot? Is it the -seemingly changing - width of the bars? If so, this seems to be an artifact due to resolution limits. In that case ry to reduce their width to something smaller, e.g. 0.1 or 0.2. – Flow Aug 16 '23 at 14:29
  • This is a duplicate of [Bar plot with irregular spacing](https://stackoverflow.com/q/58963320/7758804) – Trenton McKinney Aug 16 '23 at 19:41

1 Answers1

2

As mentioned in the comments your code doesn't reproduce your figure, and this appears to be a resolution issue. Try adjusting your figure size, the dpi, and the bar widths until you get what you want.

import matplotlib.pyplot as plt
import numpy as np

plt.figure(figsize=(10,10), dpi=600)
plt.bar(np.arange(len(y_values)), y_values, width=0.5, edgecolor="black")
plt.show()

enter image description here

astroChance
  • 337
  • 1
  • 10