python编程从入门到实践——16章

对16章西卡特和死亡谷的天气温度进行绘制在同一个表格的时候,出现绘制了两个表格的情况。代码如下:

#绘制sitka的温度图
dates, highs, lows = [], [], []
get_weather_date(‘sitka_weather_2014.csv’, dates, highs, lows)
#根据数据绘制图形
fig = plt.figure(dpi=128, figsize=(10, 6))#定义的第一个屏幕参数
plt.plot(dates, highs, c=‘red’, alpha=0.5)
plt.plot(dates, lows, c=‘red’, alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor=‘red’, alpha=0.1)

#绘制Death Valley的温度图
dates, highs, lows = [], [], []
get_weather_date(‘death_valley_2014.csv’, dates, highs, lows)
#根据数据绘制图形
fig = plt.figure(dpi=128, figsize=(10, 6))#定义的第二个屏幕参数
plt.plot(dates, highs, c=‘blue’, alpha=0.5)
plt.plot(dates, lows, c=‘blue’, alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor=‘blue’, alpha=0.1)

错误的原因是因为代码中定义了两次屏幕参数,导致绘制了两个屏幕。

在这里插入图片描述

在这里插入图片描述

以上的图片是绘制的两个图表,可见第一图表的标题,x轴等有根据代码要求绘制图形格式,而图表2则无。并且图表一的代码是位于图表而的下方,但靠近图表格式要求的代码,所以是否有个就近原则。

#绘制sitka的温度图
dates, highs, lows = [], [], []
get_weather_date(‘sitka_weather_2014.csv’, dates, highs, lows)
#根据数据绘制图形
fig = plt.figure(dpi=128, figsize=(10, 6))
plt.plot(dates, highs, c=‘red’, alpha=0.5)
plt.plot(dates, lows, c=‘red’, alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor=‘red’, alpha=0.1)

#绘制Death Valley的温度图
dates, highs, lows = [], [], []
get_weather_date(‘death_valley_2014.csv’, dates, highs, lows)
#根据数据绘制图形
fig = plt.figure(dpi=128, figsize=(10, 6))
plt.plot(dates, highs, c=‘blue’, alpha=0.5)
plt.plot(dates, lows, c=‘blue’, alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor=‘blue’, alpha=0.1)

#设置图形的格式
plt.title(“Daily high and low temperature - 2014\nDeath Valley and sitka_weather”, fontsize=24)
plt.xlabel(’’, fontsize=16)

plt.ylabel(“Temperature(F)”, fontsize=16)
plt.tick_params(axis=‘both’, which=‘major’, labelsize=16)
plt.ylim(0, 120)

plt.show()

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值