0
import pandas as pd
import matplotlib.pyplot as plt

pd.options.display.max_rows = 100
pd.set_option('display.max_columns', None)

western_counties = pd.read_csv('2018_governor_results_western_ny_dem.csv')

df = pd.DataFrame(western_counties)
X = list(df.iloc[:, 0])
Y = list(df.iloc[:, 1])


plt.bar(X, Y, color='g')
plt.title('Region 1 - Western New York')
plt.xlabel('x')
plt.ylabel('y')
plt.ylim(ymin=0)


plt.show()

I am getting the following chart. As you can see the first "bar" starts at its value (3254). I want this to actually show the green bar, which means Y axis needs to be set to zero. Any help is appreciated.

Current Chart with Code Above

Derek O
  • 16,770
  • 4
  • 24
  • 43
Connor
  • 1
  • The values in the dataframe are strings instead of numbers. See e.g. [Convert number strings with commas in pandas DataFrame to float](https://stackoverflow.com/questions/22137723/convert-number-strings-with-commas-in-pandas-dataframe-to-float) – JohanC Dec 30 '21 at 02:46

1 Answers1

0

Matplotlib doc says to use ylim(bottom=0) instead of ylim(ymin=0)

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ylim.html#

you could also just say plt.ylim([0,162772])

TheRibosome
  • 301
  • 1
  • 9