因此,目前正在学习如何导入数据并在matplotlib中使用它,我甚至遇到了麻烦,即使我从本书中获得了确切的代码.
这是情节的样子,但我的问题是如何在x轴的开始和结束之间没有空白的地方得到它.
这是代码:
import csv
from matplotlib import pyplot as plt
from datetime import datetime
# Get dates and high temperatures from file.
filename = 'sitka_weather_07-2014.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
#for index, column_header in enumerate(header_row):
#print(index, column_header)
dates, highs = [], []
for row in reader:
current_date = datetime.strptime(row[0], "%Y-%m-%d")
dates.append(current_date)
high = int(row[1])
highs.append(high)
# Plot data.
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(dates, highs, c='red')
# Format plot.
plt.title("Daily high temperatures, July 2014", fontsize=24) …Run Code Online (Sandbox Code Playgroud) 我在编辑作品时注意到了这种细微差别.
以前,matplotlib看起来像这样:
x=[1,2,3,4,5]
y=[4,5,5,2,1]
plot(x,y,'-')
Run Code Online (Sandbox Code Playgroud)
但是在最近的升级之后我相信,有偏差,这将会像这样回归
这与我现在看到的有点不相干.我想知道
如果这种偏移是数据可视化的一个很好的实践?如果是这样,我会保持原样.
如何取消这个偏移量?
我可以手动恢复限制plt.gca().set_xlim([1, 5]),但如果我有另外20个图,则无法扩展.我用Google搜索并没有找到太多关于此的信息.