Files
akmon/doc_bus/generate_charts.py
2026-01-20 08:04:15 +08:00

373 lines
15 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
融资计划书图表生成工具
Generate charts and diagrams for financing plan
"""
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import pandas as pd
from matplotlib.font_manager import FontProperties
import seaborn as sns
from datetime import datetime
import os
# 设置中文字体
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei', 'SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
class FinancingChartGenerator:
"""融资计划书图表生成器"""
def __init__(self, output_dir='charts'):
self.output_dir = output_dir
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# 设置颜色主题
self.colors = {
'primary': '#1F497D',
'secondary': '#365F91',
'accent': '#4F81BD',
'success': '#70AD47',
'warning': '#FFC000',
'danger': '#C5504B',
'light': '#F2F2F2',
'dark': '#404040'
}
def generate_market_size_chart(self):
"""生成市场规模图表"""
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
# 市场规模数据
markets = ['智能穿戴设备', '健康管理服务', '目标细分市场']
sizes = [400, 10000, 500]
colors = [self.colors['primary'], self.colors['secondary'], self.colors['accent']]
# 柱状图
bars = ax1.bar(markets, sizes, color=colors, alpha=0.8)
ax1.set_title('2025年市场规模预测亿元', fontsize=14, fontweight='bold')
ax1.set_ylabel('市场规模(亿元)')
# 添加数值标签
for bar, size in zip(bars, sizes):
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height + 50,
f'{size}亿', ha='center', va='bottom', fontweight='bold')
# 饼图 - 目标用户分布
user_segments = ['在校学生', '老年人群', '其他健康群体']
user_counts = [2.9, 2.64, 1.0]
ax2.pie(user_counts, labels=user_segments, autopct='%1.1f亿',
colors=[colors[1] for colors in [self.colors['primary'], self.colors['secondary'], self.colors['accent']]],
startangle=90)
ax2.set_title('目标用户群体分布', fontsize=14, fontweight='bold')
plt.tight_layout()
plt.savefig(f'{self.output_dir}/market_analysis.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_financial_projection(self):
"""生成财务预测图表"""
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(16, 12))
# 收入预测
years = ['2025年', '2026年', '2027年']
revenues = [2000, 8000, 30000]
ax1.plot(years, revenues, marker='o', linewidth=3, markersize=8,
color=self.colors['primary'])
ax1.fill_between(years, revenues, alpha=0.3, color=self.colors['primary'])
ax1.set_title('收入预测(万元)', fontsize=14, fontweight='bold')
ax1.set_ylabel('收入(万元)')
ax1.grid(True, alpha=0.3)
# 添加数值标签
for i, (year, revenue) in enumerate(zip(years, revenues)):
ax1.text(i, revenue + 1000, f'{revenue}', ha='center', va='bottom', fontweight='bold')
# 收入结构 - 2027年预测
revenue_types = ['硬件销售', '平台服务', '数据服务', '数字资产']
revenue_values = [12000, 10000, 5000, 3000]
wedges, texts, autotexts = ax2.pie(revenue_values, labels=revenue_types, autopct='%1.1f%%',
colors=[self.colors['primary'], self.colors['secondary'],
self.colors['accent'], self.colors['success']])
ax2.set_title('2027年收入结构预测', fontsize=14, fontweight='bold')
# 成本结构分析
cost_types = ['硬件采购\n40%', '销售费用\n15%', '运营服务\n20%', '其他成本\n25%']
cost_percentages = [40, 15, 20, 25]
bars = ax3.barh(cost_types, cost_percentages,
color=[self.colors['danger'], self.colors['warning'],
self.colors['accent'], self.colors['dark']])
ax3.set_title('成本结构分析', fontsize=14, fontweight='bold')
ax3.set_xlabel('占收入比例(%')
# 盈利能力分析
years_profit = ['2025年', '2026年', '2027年']
gross_margin = [60, 60, 60]
net_margin = [15, 25, 30]
x = np.arange(len(years_profit))
width = 0.35
ax4.bar(x - width/2, gross_margin, width, label='毛利率', color=self.colors['success'])
ax4.bar(x + width/2, net_margin, width, label='净利率', color=self.colors['primary'])
ax4.set_title('盈利能力分析', fontsize=14, fontweight='bold')
ax4.set_ylabel('利润率(%')
ax4.set_xticks(x)
ax4.set_xticklabels(years_profit)
ax4.legend()
ax4.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig(f'{self.output_dir}/financial_projection.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_business_model_flow(self):
"""生成商业模式流程图"""
fig, ax = plt.subplots(figsize=(14, 10))
# 定义流程节点
nodes = [
{'name': '数据采集层', 'pos': (2, 8), 'color': self.colors['primary']},
{'name': '数据传输层', 'pos': (4, 8), 'color': self.colors['secondary']},
{'name': '数据处理层', 'pos': (6, 8), 'color': self.colors['accent']},
{'name': '数据存储层', 'pos': (8, 8), 'color': self.colors['success']},
{'name': '数据分析层', 'pos': (10, 8), 'color': self.colors['warning']},
{'name': '价值输出层', 'pos': (10, 6), 'color': self.colors['danger']},
{'name': '资产确权层', 'pos': (8, 4), 'color': self.colors['primary']},
{'name': '价值变现层', 'pos': (4, 4), 'color': self.colors['secondary']},
]
# 绘制节点
for node in nodes:
circle = patches.Circle(node['pos'], 0.8, facecolor=node['color'],
edgecolor='white', linewidth=2, alpha=0.8)
ax.add_patch(circle)
ax.text(node['pos'][0], node['pos'][1], node['name'],
ha='center', va='center', fontsize=10, fontweight='bold', color='white')
# 绘制连接线
connections = [
((2, 8), (4, 8)), ((4, 8), (6, 8)), ((6, 8), (8, 8)),
((8, 8), (10, 8)), ((10, 8), (10, 6)), ((10, 6), (8, 4)),
((8, 4), (4, 4)), ((4, 4), (2, 8))
]
for start, end in connections:
ax.annotate('', xy=end, xytext=start,
arrowprops=dict(arrowstyle='->', lw=2, color=self.colors['dark']))
# 添加硬件设备
hardware = [
{'name': '智能手环', 'pos': (1, 6)},
{'name': '基站设备', 'pos': (2, 6)},
{'name': '摄像设备', 'pos': (3, 6)}
]
for hw in hardware:
rect = patches.Rectangle((hw['pos'][0]-0.4, hw['pos'][1]-0.3), 0.8, 0.6,
facecolor=self.colors['light'], edgecolor=self.colors['dark'])
ax.add_patch(rect)
ax.text(hw['pos'][0], hw['pos'][1], hw['name'],
ha='center', va='center', fontsize=8)
ax.set_xlim(0, 12)
ax.set_ylim(2, 10)
ax.set_aspect('equal')
ax.axis('off')
ax.set_title('全生命周期AI监测商业模式闭环', fontsize=16, fontweight='bold', pad=20)
plt.tight_layout()
plt.savefig(f'{self.output_dir}/business_model_flow.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_competition_matrix(self):
"""生成竞争力矩阵图"""
fig, ax = plt.subplots(figsize=(12, 8))
# 竞争维度数据
dimensions = ['技术创新', '商业模式', '成本优势', '客户粘性']
competitive_advantage = [5, 5, 5, 4]
technical_barrier = [5, 4, 3, 4]
market_impact = [5, 5, 4, 5]
x = np.arange(len(dimensions))
width = 0.25
bars1 = ax.bar(x - width, competitive_advantage, width, label='竞争优势',
color=self.colors['primary'], alpha=0.8)
bars2 = ax.bar(x, technical_barrier, width, label='技术壁垒',
color=self.colors['secondary'], alpha=0.8)
bars3 = ax.bar(x + width, market_impact, width, label='市场影响',
color=self.colors['accent'], alpha=0.8)
ax.set_title('核心竞争力矩阵分析', fontsize=16, fontweight='bold')
ax.set_ylabel('评分1-5分')
ax.set_xticks(x)
ax.set_xticklabels(dimensions)
ax.legend()
ax.grid(True, alpha=0.3)
ax.set_ylim(0, 6)
# 添加数值标签
for bars in [bars1, bars2, bars3]:
for bar in bars:
height = bar.get_height()
ax.text(bar.get_x() + bar.get_width()/2., height + 0.1,
f'{height}', ha='center', va='bottom', fontweight='bold')
plt.tight_layout()
plt.savefig(f'{self.output_dir}/competition_matrix.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_data_value_chain(self):
"""生成数据价值递增模型"""
fig, ax = plt.subplots(figsize=(14, 6))
stages = ['原始数据', '清洗数据', '分析数据', '洞察数据', '资产数据']
values = [1, 2, 5, 10, 50]
# 创建阶梯式增长图
x_pos = np.arange(len(stages))
bars = ax.bar(x_pos, values, color=[self.colors['primary'], self.colors['secondary'],
self.colors['accent'], self.colors['success'],
self.colors['warning']], alpha=0.8)
# 添加连接线
for i in range(len(stages)-1):
ax.annotate('', xy=(x_pos[i+1], values[i+1]), xytext=(x_pos[i], values[i]),
arrowprops=dict(arrowstyle='->', lw=2, color=self.colors['dark']))
ax.set_title('数据价值递增模型', fontsize=16, fontweight='bold')
ax.set_ylabel('价值倍数')
ax.set_xticks(x_pos)
ax.set_xticklabels(stages)
ax.grid(True, alpha=0.3)
# 添加数值标签
for bar, value in zip(bars, values):
height = bar.get_height()
ax.text(bar.get_x() + bar.get_width()/2., height + 1,
f'{value}', ha='center', va='bottom', fontweight='bold', fontsize=12)
plt.tight_layout()
plt.savefig(f'{self.output_dir}/data_value_chain.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_investment_return_chart(self):
"""生成投资回报分析图"""
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(16, 12))
# 三阶段融资规模
stages = ['第一阶段\n2025年', '第二阶段\n2026年', '第三阶段\n2027年']
funding_amounts = [1000, 6000, 30000]
bars = ax1.bar(stages, funding_amounts,
color=[self.colors['primary'], self.colors['secondary'], self.colors['accent']])
ax1.set_title('三阶段融资计划(万元)', fontsize=14, fontweight='bold')
ax1.set_ylabel('融资金额(万元)')
for bar, amount in zip(bars, funding_amounts):
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height + 500,
f'{amount}', ha='center', va='bottom', fontweight='bold')
# 投资回报倍数
investment_stages = ['第一阶段', '第二阶段', '整体投资']
return_multiples = [1.8, 4, 20]
ax2.bar(investment_stages, return_multiples,
color=[self.colors['success'], self.colors['warning'], self.colors['danger']])
ax2.set_title('预期投资回报倍数', fontsize=14, fontweight='bold')
ax2.set_ylabel('回报倍数')
# 公司估值增长
years = [2025, 2026, 2027, 2028, 2030]
valuations = [0.5, 2, 15, 30, 50]
ax3.plot(years, valuations, marker='o', linewidth=3, markersize=8,
color=self.colors['primary'])
ax3.fill_between(years, valuations, alpha=0.3, color=self.colors['primary'])
ax3.set_title('公司估值预测(亿元)', fontsize=14, fontweight='bold')
ax3.set_ylabel('估值(亿元)')
ax3.grid(True, alpha=0.3)
# 股权结构变化
stages_equity = ['初始', '第一轮后', '第二轮后', '上市后']
original_equity = [100, 80, 60, 45]
investor_equity = [0, 20, 40, 55]
width = 0.6
ax4.bar(stages_equity, original_equity, width, label='原股东',
color=self.colors['primary'])
ax4.bar(stages_equity, investor_equity, width, bottom=original_equity,
label='投资者', color=self.colors['secondary'])
ax4.set_title('股权结构变化', fontsize=14, fontweight='bold')
ax4.set_ylabel('股权比例(%')
ax4.legend()
plt.tight_layout()
plt.savefig(f'{self.output_dir}/investment_return.png', dpi=300, bbox_inches='tight')
plt.close()
def generate_all_charts(self):
"""生成所有图表"""
print("正在生成融资计划书图表...")
try:
print("1. 生成市场分析图表...")
self.generate_market_size_chart()
print("2. 生成财务预测图表...")
self.generate_financial_projection()
print("3. 生成商业模式流程图...")
self.generate_business_model_flow()
print("4. 生成竞争力矩阵图...")
self.generate_competition_matrix()
print("5. 生成数据价值链图...")
self.generate_data_value_chain()
print("6. 生成投资回报分析图...")
self.generate_investment_return_chart()
print(f"\n✅ 所有图表已生成完成!")
print(f"📁 图表保存位置: {self.output_dir}/")
print("📄 生成的图表文件:")
chart_files = [
"market_analysis.png - 市场分析图表",
"financial_projection.png - 财务预测图表",
"business_model_flow.png - 商业模式流程图",
"competition_matrix.png - 竞争力矩阵图",
"data_value_chain.png - 数据价值链图",
"investment_return.png - 投资回报分析图"
]
for file in chart_files:
print(f" 📊 {file}")
except Exception as e:
print(f"❌ 图表生成失败: {e}")
return False
return True
def main():
"""主函数"""
generator = FinancingChartGenerator()
generator.generate_all_charts()
if __name__ == '__main__':
main()