某户全年每月的电费统计如下:220, 175, 198, 187,190,260,350,320,330,230,290,330元。请采用折线图表示电费的每月浮动趋势。 2.某城市四季平均最高气温为23, 34, 26, 17,平均湿度60,75,55,48,请按照如下要求绘制共享坐标轴图像。 (1)温度显示为柱状图(左侧y轴),适度显示为折线图(右侧y轴) (2)x轴为季节,刻度标签字号12,倾斜20度。 (3)左侧y轴标签“平均温度“设为绿色。 (4)右侧y轴代表平均湿度,下限设为40。 (5)柱状图图例显示左上,折线图图例显示右上。
时间: 2023-08-08 19:05:21 浏览: 50
1. 电费折线图:
![电费折线图](https://i.imgur.com/u6e1mWd.png)
2. 温度柱状图和湿度折线图共享坐标轴图像:
![温度和湿度共享坐标轴图像](https://i.imgur.com/rYhFgQZ.png)
代码:
```python
import matplotlib.pyplot as plt
# 电费数据
electricity = [220, 175, 198, 187, 190, 260, 350, 320, 330, 230, 290, 330]
# 电费折线图
plt.plot(electricity, marker='o')
plt.title('Monthly Electricity Expenses')
plt.xlabel('Month')
plt.ylabel('Electricity Cost (yuan)')
plt.show()
# 温度和湿度数据
temperature = [23, 34, 26, 17]
humidity = [60, 75, 55, 48]
# 温度柱状图和湿度折线图共享坐标轴图像
fig, ax1 = plt.subplots()
ax1.bar(['Spring', 'Summer', 'Fall', 'Winter'], temperature, color='orange')
ax1.set_ylabel('Average Temperature', color='green')
ax1.tick_params(axis='y', labelcolor='green')
ax1.yaxis.labelpad = 15
ax2 = ax1.twinx()
ax2.plot(['Spring', 'Summer', 'Fall', 'Winter'], humidity, color='blue', marker='o')
ax2.set_ylabel('Average Humidity', color='blue')
ax2.tick_params(axis='y', labelcolor='blue')
ax2.yaxis.set_label_coords(1.1, 0.5)
ax2.set_ylim(bottom=40)
plt.title('Seasonal Temperature and Humidity')
plt.xlabel('Season', fontsize=12)
plt.xticks(rotation=20, ha='right')
plt.legend(['Humidity'], loc='upper right')
plt.legend(['Temperature'], loc='upper left')
plt.show()
```