0

I tried a simple line plot using matplotlib using the code as below.

kss_date= ['2017-10-17', '2017-10-19', '2017-10-20', '2018-09-20', '2018-09-21', '2019-09-03', '2019-09-04']
kss_conc = ['12.3', '12.6', '13.0', '12.2', '11.2', '9.9', '10.5']

plt.plot(kss_date, kss_conc,'.-')
plt.xlabel('Date')
plt.ylabel('Concentration')
plt.xticks(rotation = 90)
plt.show()

I see that the y axis not increasing gradually as in the image. I want the bottom most value to be 9.9 and the top to be 13.0. I tried plt.ylim() but it didn't help. Can someone please explain me what is happening?see y-axis.

Newbieee16
  • 43
  • 5

1 Answers1

1

The problem is that you are plotting strings as the content of kss_conc. You should convert to floats like:

kss_conc = ['12.3', '12.6', '13.0', '12.2', '11.2', '9.9', '10.5']
kss_conc = list(map(float, kss_conc))

Before plotting. Then, you can use plt.ylim([9.9, 13.0]) and it should work.

Maura Pintor
  • 198
  • 1
  • 14