1.1 数据分析

1.1 分析公司利润数据得出公司近五年(2018到2022年)营业总收入和营业总成本,使用折柱混合图展示。(20分,简单)
下面是一个使用Python和Matplotlib库分析公司利润数据并展示折柱混合图的示例代码:

import json
import matplotlib.pyplot as plt
 # 读取数据文件
with open('data.json', 'r', encoding='utf-8') as f:
    data = json.load(f)
 # 提取近五年的数据
recent_years_data = data[-5:]
 # 提取营业总收入和营业总成本数据
years = [int(item['年份']) for item in recent_years_data]
revenue = [float(item['营业收入']) for item in recent_years_data]
cost = [float(item['营业成本']) for item in recent_years_data]
 # 绘制折线图和柱状图
fig, ax1 = plt.subplots()
 # 绘制折线图
ax1.plot(years, revenue, marker='o', color='blue', label='营业总收入')
ax1.plot(years, cost, marker='o', color='red', label='营业总成本')
ax1.set_xlabel('年份')
ax1.set_ylabel('金额(单位:亿元)')
 # 绘制柱状图
ax2 = ax1.twinx()
ax2.bar(years, cost, alpha=0.3, color='red', label='营业总成本')
ax2.set_ylabel('金额(单位:亿元)')
 # 添加图例
ax1.legend(loc='upper left')
ax2.legend(loc='upper right')
 # 设置标题
plt.title('公司近五年营业总收入和营业总成本')
 # 展示图形
plt.show()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容