我正在編寫的應用程序將日期時間和溫度觀察對的CSV數據解析到另一個城市的同一時間寫一份報告和一張散點圖。一切正常,除了散點圖顯示的是從x軸中心開始的點的垂直線,而不是x軸上每個列出的日期之上的點。matplotlib中的散點顯示圖表中心的垂直線,而不是相應的X軸值
這是圍繞我的matplotlib應用程序的代碼。
import matplotlib.pyplot as pp
.
.
.
# Code that imports the CSV, changes the times to the other city ....
.
.
.
paris_stamps = [] # This list is a list of datetimes that compose the X axis
i = 0
while i < len(parsedObservations):
paris_stamps.append(parsedObservations[i][1])
i += 1
observed_values = [] # these are the temperatures that go on the X axis
i = 0
while i < len(parsedObservations):
observed_values.append(parsedObservations[i][0])
i += 1
# the code below is the interaction with matplotlib
paris_stamps = [pandas.to_datetime(d) for d in paris_stamps] # sanitize the string datetimes to a format matplotlib will accept
pp.scatter(x = paris_stamps,y = observed_values, s = 500, c='blue')
pp.show()
當我運行它,我得到這個爲圖表:Chart with a vertical line of dots instead of a horizontal series of dots above each of the x axis values
- 我如何獲得matplotlib散點圖一個真正的X,Y配對圖表在這種情況下格式化?
問題尋求幫助調試(「?爲什麼不是這個代碼工作」)必須包括所期望的行爲,一個特定的問題或錯誤,以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建[mcve]。 – ImportanceOfBeingErnest