vizpaint 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vizpaint-0.1.0/PKG-INFO +12 -0
- vizpaint-0.1.0/setup.cfg +4 -0
- vizpaint-0.1.0/setup.py +11 -0
- vizpaint-0.1.0/vizpaint/__init__.py +106 -0
- vizpaint-0.1.0/vizpaint/area_chart.py +64 -0
- vizpaint-0.1.0/vizpaint/bar_chart.py +32 -0
- vizpaint-0.1.0/vizpaint/box_plot.py +72 -0
- vizpaint-0.1.0/vizpaint/bubble_chart.py +83 -0
- vizpaint-0.1.0/vizpaint/curve_statistical_chart.py +30 -0
- vizpaint-0.1.0/vizpaint/heatmap.py +60 -0
- vizpaint-0.1.0/vizpaint/histogram.py +79 -0
- vizpaint-0.1.0/vizpaint/line_plot.py +70 -0
- vizpaint-0.1.0/vizpaint/paintchart.py +33 -0
- vizpaint-0.1.0/vizpaint/pair_plot.py +86 -0
- vizpaint-0.1.0/vizpaint/pie_chart.py +22 -0
- vizpaint-0.1.0/vizpaint/quiver_plot.py +15 -0
- vizpaint-0.1.0/vizpaint/radar_chart.py +72 -0
- vizpaint-0.1.0/vizpaint/rose_chart.py +433 -0
- vizpaint-0.1.0/vizpaint/scatter_3d.py +22 -0
- vizpaint-0.1.0/vizpaint/scatter_plot.py +19 -0
- vizpaint-0.1.0/vizpaint/stacked_bar_chart.py +80 -0
- vizpaint-0.1.0/vizpaint/stream_plot.py +23 -0
- vizpaint-0.1.0/vizpaint/surface_3d.py +21 -0
- vizpaint-0.1.0/vizpaint/treemap.py +24 -0
- vizpaint-0.1.0/vizpaint/violin_plot.py +68 -0
- vizpaint-0.1.0/vizpaint.egg-info/PKG-INFO +12 -0
- vizpaint-0.1.0/vizpaint.egg-info/SOURCES.txt +33 -0
- vizpaint-0.1.0/vizpaint.egg-info/dependency_links.txt +1 -0
- vizpaint-0.1.0/vizpaint.egg-info/requires.txt +2 -0
- vizpaint-0.1.0/vizpaint.egg-info/top_level.txt +2 -0
- vizpaint-0.1.0//346/250/241/345/235/227/__init__.py +0 -0
- vizpaint-0.1.0//346/250/241/345/235/227/ee.py +2 -0
- vizpaint-0.1.0//346/250/241/345/235/227/g/__init__.py +0 -0
- vizpaint-0.1.0//346/250/241/345/235/227/g/cemath.py +35 -0
- vizpaint-0.1.0//346/250/241/345/235/227/g/jj.py +1 -0
vizpaint-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vizpaint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A comprehensive data visualization library
|
|
5
|
+
Author: Your Name
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Requires-Dist: matplotlib>=3.3
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: requires-dist
|
|
11
|
+
Dynamic: requires-python
|
|
12
|
+
Dynamic: summary
|
vizpaint-0.1.0/setup.cfg
ADDED
vizpaint-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="vizpaint", # 包名,在PyPI上必须唯一
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
author="Your Name",
|
|
7
|
+
description="A comprehensive data visualization library",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
install_requires=["matplotlib>=3.3", "numpy"], # 关键依赖
|
|
10
|
+
python_requires=">=3.7",
|
|
11
|
+
)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# paint/__init__.py
|
|
4
|
+
""""
|
|
5
|
+
Paint Chart Package - 图表绘制工具包
|
|
6
|
+
提供丰富的图表绘制功能
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
__author__ = "Chart Package Team"
|
|
11
|
+
|
|
12
|
+
# 定义所有可导出的函数
|
|
13
|
+
__all__ = [
|
|
14
|
+
# 基础图表
|
|
15
|
+
'pie_chart',
|
|
16
|
+
'bar_chart',
|
|
17
|
+
'curve_statistical_chart',
|
|
18
|
+
'scatter_plot',
|
|
19
|
+
# 新增图表类型
|
|
20
|
+
'line_plot',
|
|
21
|
+
'histogram',
|
|
22
|
+
'box_plot',
|
|
23
|
+
'area_chart',
|
|
24
|
+
'radar_chart',
|
|
25
|
+
'heatmap',
|
|
26
|
+
'pair_plot',
|
|
27
|
+
'violin_plot',
|
|
28
|
+
'bubble_chart',
|
|
29
|
+
'stacked_bar_chart',
|
|
30
|
+
# 实用函数
|
|
31
|
+
'set_style',
|
|
32
|
+
'show_all',
|
|
33
|
+
'clear_all',
|
|
34
|
+
'save_figure',
|
|
35
|
+
'get_version',
|
|
36
|
+
'create_subplots',
|
|
37
|
+
'rose_chart',
|
|
38
|
+
'surface_3d',
|
|
39
|
+
'scatter_3d',
|
|
40
|
+
'stream_plot',
|
|
41
|
+
'treemap',
|
|
42
|
+
'quiver_plot'
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
# 导入基础图表函数
|
|
46
|
+
from .pie_chart import pie_chart
|
|
47
|
+
from .bar_chart import bar_chart
|
|
48
|
+
from .curve_statistical_chart import curve_statistical_chart
|
|
49
|
+
from .scatter_plot import scatter_plot
|
|
50
|
+
|
|
51
|
+
# 导入新增图表函数
|
|
52
|
+
from .line_plot import line_plot
|
|
53
|
+
from .histogram import histogram
|
|
54
|
+
from .box_plot import box_plot
|
|
55
|
+
from .area_chart import area_chart
|
|
56
|
+
from .radar_chart import radar_chart
|
|
57
|
+
from .heatmap import heatmap
|
|
58
|
+
from .pair_plot import pair_plot
|
|
59
|
+
from .violin_plot import violin_plot
|
|
60
|
+
from .bubble_chart import bubble_chart
|
|
61
|
+
from .stacked_bar_chart import stacked_bar_chart
|
|
62
|
+
from .rose_chart import rose_chart
|
|
63
|
+
from .surface_3d import surface_3d
|
|
64
|
+
from .scatter_3d import scatter_3d
|
|
65
|
+
from .stream_plot import stream_plot
|
|
66
|
+
from .treemap import treemap
|
|
67
|
+
from .quiver_plot import quiver_plot
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# 导入实用函数
|
|
71
|
+
import matplotlib.pyplot as plt
|
|
72
|
+
import numpy as np
|
|
73
|
+
|
|
74
|
+
def set_style(style='default'):
|
|
75
|
+
"""设置图表样式"""
|
|
76
|
+
try:
|
|
77
|
+
plt.style.use(style)
|
|
78
|
+
return True
|
|
79
|
+
except:
|
|
80
|
+
plt.style.use('default')
|
|
81
|
+
print(f"样式 '{style}' 不可用,使用默认样式")
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
def show_all():
|
|
85
|
+
"""显示所有图表"""
|
|
86
|
+
plt.show()
|
|
87
|
+
|
|
88
|
+
def clear_all():
|
|
89
|
+
"""清除所有图表"""
|
|
90
|
+
plt.close('all')
|
|
91
|
+
|
|
92
|
+
def save_figure(filename, dpi=300, transparent=False):
|
|
93
|
+
"""保存当前图表"""
|
|
94
|
+
plt.savefig(filename, dpi=dpi, transparent=transparent,
|
|
95
|
+
bbox_inches='tight')
|
|
96
|
+
plt.close()
|
|
97
|
+
|
|
98
|
+
def get_version():
|
|
99
|
+
"""获取包版本"""
|
|
100
|
+
return __version__
|
|
101
|
+
|
|
102
|
+
def create_subplots(nrows=1, ncols=1, figsize=(10, 8), **kwargs):
|
|
103
|
+
"""创建子图布局"""
|
|
104
|
+
return plt.subplots(nrows, ncols, figsize=figsize, **kwargs)
|
|
105
|
+
|
|
106
|
+
# 包初始化消息
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# paint/area_chart.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def area_chart(x_data=None, y_data_list=None, labels=None,
|
|
7
|
+
title="Area Chart", xlabel="X", ylabel="Y",
|
|
8
|
+
colors=None, alpha=0.5, stacked=False):
|
|
9
|
+
"""
|
|
10
|
+
绘制面积图
|
|
11
|
+
|
|
12
|
+
参数:
|
|
13
|
+
x_data: X轴数据
|
|
14
|
+
y_data_list: Y轴数据列表
|
|
15
|
+
labels: 数据标签
|
|
16
|
+
title: 图表标题
|
|
17
|
+
xlabel: X轴标签
|
|
18
|
+
ylabel: Y轴标签
|
|
19
|
+
colors: 颜色列表
|
|
20
|
+
alpha: 透明度
|
|
21
|
+
stacked: 是否堆叠
|
|
22
|
+
"""
|
|
23
|
+
fig, ax = plt.subplots(figsize=(10, 6))
|
|
24
|
+
|
|
25
|
+
# 生成默认数据
|
|
26
|
+
if x_data is None:
|
|
27
|
+
x_data = np.arange(1, 11)
|
|
28
|
+
if y_data_list is None:
|
|
29
|
+
y_data_list = [
|
|
30
|
+
np.random.randint(10, 50, 10),
|
|
31
|
+
np.random.randint(20, 60, 10),
|
|
32
|
+
np.random.randint(5, 40, 10)
|
|
33
|
+
]
|
|
34
|
+
labels = ['Product A', 'Product B', 'Product C']
|
|
35
|
+
|
|
36
|
+
# 设置默认颜色
|
|
37
|
+
if colors is None:
|
|
38
|
+
colors = plt.cm.Pastel1(np.linspace(0, 1, len(y_data_list)))
|
|
39
|
+
|
|
40
|
+
# 绘制面积图
|
|
41
|
+
if stacked:
|
|
42
|
+
# 堆叠面积图
|
|
43
|
+
y_stacked = np.vstack(y_data_list)
|
|
44
|
+
ax.stackplot(x_data, y_stacked, labels=labels,
|
|
45
|
+
colors=colors, alpha=alpha)
|
|
46
|
+
else:
|
|
47
|
+
# 普通面积图
|
|
48
|
+
for i, y_data in enumerate(y_data_list):
|
|
49
|
+
ax.fill_between(x_data, 0, y_data,
|
|
50
|
+
alpha=alpha, color=colors[i % len(colors)],
|
|
51
|
+
label=labels[i] if labels else None)
|
|
52
|
+
|
|
53
|
+
# 设置图表属性
|
|
54
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
55
|
+
ax.set_xlabel(xlabel, fontsize=12)
|
|
56
|
+
ax.set_ylabel(ylabel, fontsize=12)
|
|
57
|
+
|
|
58
|
+
ax.grid(True, linestyle='--', alpha=0.3)
|
|
59
|
+
|
|
60
|
+
if labels:
|
|
61
|
+
ax.legend(fontsize=10, loc='best')
|
|
62
|
+
|
|
63
|
+
plt.tight_layout()
|
|
64
|
+
return fig, ax
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# paint/bar_chart.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def bar_chart(a, b, c, d, e, f):
|
|
7
|
+
"""
|
|
8
|
+
绘制条形图
|
|
9
|
+
|
|
10
|
+
参数:
|
|
11
|
+
a,b,c,d,e: 条形的高度值
|
|
12
|
+
f: 条形的颜色
|
|
13
|
+
"""
|
|
14
|
+
n = 6 # 6个条形
|
|
15
|
+
y = [a, b, c, d, e, 0] # 你只给了5个值,所以第6个设为0
|
|
16
|
+
index = np.arange(n)
|
|
17
|
+
|
|
18
|
+
plt.figure(figsize=(10, 6))
|
|
19
|
+
plt.bar(index, y, color=f, edgecolor='black', alpha=0.8)
|
|
20
|
+
|
|
21
|
+
# 添加标签
|
|
22
|
+
plt.xlabel('类别')
|
|
23
|
+
plt.ylabel('数值')
|
|
24
|
+
plt.title('条形图')
|
|
25
|
+
plt.xticks(index, ['A', 'B', 'C', 'D', 'E', 'F'])
|
|
26
|
+
|
|
27
|
+
# 在条形上显示数值
|
|
28
|
+
for i, v in enumerate(y):
|
|
29
|
+
plt.text(i, v + 0.02, str(v), ha='center', va='bottom')
|
|
30
|
+
|
|
31
|
+
plt.tight_layout()
|
|
32
|
+
plt.show()
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# paint/box_plot.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def box_plot(data_list=None, labels=None, title="Box Plot",
|
|
7
|
+
ylabel="Value", colors=None, show_mean=False,
|
|
8
|
+
show_points=False, horizontal=False):
|
|
9
|
+
"""
|
|
10
|
+
绘制箱线图
|
|
11
|
+
|
|
12
|
+
参数:
|
|
13
|
+
data_list: 数据列表(每个元素是一个数据集)
|
|
14
|
+
labels: 数据集标签
|
|
15
|
+
title: 图表标题
|
|
16
|
+
ylabel: Y轴标签
|
|
17
|
+
colors: 颜色列表
|
|
18
|
+
show_mean: 是否显示均值
|
|
19
|
+
show_points: 是否显示数据点
|
|
20
|
+
horizontal: 是否水平显示
|
|
21
|
+
"""
|
|
22
|
+
fig, ax = plt.subplots(figsize=(10, 6))
|
|
23
|
+
|
|
24
|
+
# 生成默认数据
|
|
25
|
+
if data_list is None:
|
|
26
|
+
np.random.seed(42)
|
|
27
|
+
data_list = [
|
|
28
|
+
np.random.normal(0, 1, 100),
|
|
29
|
+
np.random.normal(2, 1.5, 100),
|
|
30
|
+
np.random.normal(-1, 0.5, 100),
|
|
31
|
+
np.random.normal(3, 2, 100)
|
|
32
|
+
]
|
|
33
|
+
labels = ['Group A', 'Group B', 'Group C', 'Group D']
|
|
34
|
+
|
|
35
|
+
# 设置默认颜色
|
|
36
|
+
if colors is None:
|
|
37
|
+
colors = plt.cm.Set2(np.linspace(0, 1, len(data_list)))
|
|
38
|
+
|
|
39
|
+
# 绘制箱线图
|
|
40
|
+
bp = ax.boxplot(data_list, labels=labels, patch_artist=True,
|
|
41
|
+
showmeans=show_mean, showfliers=show_points,
|
|
42
|
+
vert=not horizontal)
|
|
43
|
+
|
|
44
|
+
# 设置箱子颜色
|
|
45
|
+
for patch, color in zip(bp['boxes'], colors):
|
|
46
|
+
patch.set_facecolor(color)
|
|
47
|
+
patch.set_alpha(0.7)
|
|
48
|
+
|
|
49
|
+
# 设置其他元素颜色
|
|
50
|
+
for element in ['whiskers', 'caps', 'medians']:
|
|
51
|
+
for line in bp[element]:
|
|
52
|
+
line.set_color('black')
|
|
53
|
+
line.set_linewidth(1.5)
|
|
54
|
+
|
|
55
|
+
# 设置均值点
|
|
56
|
+
if show_mean:
|
|
57
|
+
for mean_line in bp['means']:
|
|
58
|
+
mean_line.set_color('red')
|
|
59
|
+
mean_line.set_linewidth(2)
|
|
60
|
+
|
|
61
|
+
# 设置图表属性
|
|
62
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
63
|
+
ax.set_ylabel(ylabel, fontsize=12)
|
|
64
|
+
|
|
65
|
+
if horizontal:
|
|
66
|
+
ax.set_xlabel(ylabel, fontsize=12)
|
|
67
|
+
ax.set_ylabel('Groups', fontsize=12)
|
|
68
|
+
|
|
69
|
+
ax.grid(True, linestyle='--', alpha=0.3, axis='y' if not horizontal else 'x')
|
|
70
|
+
|
|
71
|
+
plt.tight_layout()
|
|
72
|
+
return fig, ax, bp
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# paint/bubble_chart.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def bubble_chart(x_data=None, y_data=None, size_data=None,
|
|
7
|
+
color_data=None, labels=None, title="Bubble Chart",
|
|
8
|
+
xlabel="X", ylabel="Y", cmap='viridis',
|
|
9
|
+
alpha=0.6, edgecolors='black'):
|
|
10
|
+
"""
|
|
11
|
+
绘制气泡图
|
|
12
|
+
|
|
13
|
+
参数:
|
|
14
|
+
x_data: X轴数据
|
|
15
|
+
y_data: Y轴数据
|
|
16
|
+
size_data: 气泡大小数据
|
|
17
|
+
color_data: 气泡颜色数据
|
|
18
|
+
labels: 气泡标签
|
|
19
|
+
title: 图表标题
|
|
20
|
+
xlabel: X轴标签
|
|
21
|
+
ylabel: Y轴标签
|
|
22
|
+
cmap: 颜色映射
|
|
23
|
+
alpha: 透明度
|
|
24
|
+
edgecolors: 边框颜色
|
|
25
|
+
"""
|
|
26
|
+
fig, ax = plt.subplots(figsize=(10, 8))
|
|
27
|
+
|
|
28
|
+
# 生成默认数据
|
|
29
|
+
if x_data is None:
|
|
30
|
+
np.random.seed(42)
|
|
31
|
+
n_points = 30
|
|
32
|
+
x_data = np.random.rand(n_points) * 100
|
|
33
|
+
y_data = np.random.rand(n_points) * 100
|
|
34
|
+
size_data = np.random.rand(n_points) * 1000
|
|
35
|
+
color_data = np.random.rand(n_points)
|
|
36
|
+
labels = [f'Point {i + 1}' for i in range(n_points)]
|
|
37
|
+
|
|
38
|
+
# 归一化大小数据用于绘图
|
|
39
|
+
if size_data is not None:
|
|
40
|
+
size_normalized = (size_data - np.min(size_data)) / (np.max(size_data) - np.min(size_data))
|
|
41
|
+
sizes = 50 + size_normalized * 500
|
|
42
|
+
else:
|
|
43
|
+
sizes = 100
|
|
44
|
+
|
|
45
|
+
# 绘制气泡图
|
|
46
|
+
scatter = ax.scatter(x_data, y_data, s=sizes,
|
|
47
|
+
c=color_data, cmap=cmap,
|
|
48
|
+
alpha=alpha, edgecolors=edgecolors,
|
|
49
|
+
linewidth=1)
|
|
50
|
+
|
|
51
|
+
# 添加标签(可选)
|
|
52
|
+
if labels:
|
|
53
|
+
for i, label in enumerate(labels):
|
|
54
|
+
ax.annotate(label, (x_data[i], y_data[i]),
|
|
55
|
+
xytext=(5, 5), textcoords='offset points',
|
|
56
|
+
fontsize=9, alpha=0.7)
|
|
57
|
+
|
|
58
|
+
# 设置图表属性
|
|
59
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
60
|
+
ax.set_xlabel(xlabel, fontsize=12)
|
|
61
|
+
ax.set_ylabel(ylabel, fontsize=12)
|
|
62
|
+
|
|
63
|
+
ax.grid(True, linestyle='--', alpha=0.5)
|
|
64
|
+
|
|
65
|
+
# 添加颜色条(如果有颜色数据)
|
|
66
|
+
if color_data is not None:
|
|
67
|
+
cbar = fig.colorbar(scatter, ax=ax)
|
|
68
|
+
cbar.set_label('Color Value', fontsize=10)
|
|
69
|
+
|
|
70
|
+
# 添加图例表示气泡大小(可选)
|
|
71
|
+
if size_data is not None:
|
|
72
|
+
# 创建气泡大小示例
|
|
73
|
+
min_size = np.min(size_data)
|
|
74
|
+
max_size = np.max(size_data)
|
|
75
|
+
median_size = np.median(size_data)
|
|
76
|
+
|
|
77
|
+
legend_text = f'Bubble Size\nMin: {min_size:.1f}\nMed: {median_size:.1f}\nMax: {max_size:.1f}'
|
|
78
|
+
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
|
|
79
|
+
ax.text(0.02, 0.98, legend_text, transform=ax.transAxes, fontsize=9,
|
|
80
|
+
verticalalignment='top', bbox=props)
|
|
81
|
+
|
|
82
|
+
plt.tight_layout()
|
|
83
|
+
return fig, ax, scatter
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# paint/curve_statistical_chart.py
|
|
2
|
+
from matplotlib.pyplot import *
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def curve_statistical_chart(a, b, c, d):
|
|
7
|
+
"""
|
|
8
|
+
绘制曲线统计图
|
|
9
|
+
|
|
10
|
+
参数:
|
|
11
|
+
a: 数据点数量
|
|
12
|
+
b: 图表标题
|
|
13
|
+
c: X轴标签
|
|
14
|
+
d: Y轴标签
|
|
15
|
+
"""
|
|
16
|
+
x = np.linspace(0, 3 * np.pi, a)
|
|
17
|
+
y1, y2 = np.sin(x), np.cos(x)
|
|
18
|
+
|
|
19
|
+
plot(x, y1, label='sin(x)')
|
|
20
|
+
plot(x, y2, label='cos(x)')
|
|
21
|
+
title(b)
|
|
22
|
+
xlabel(c)
|
|
23
|
+
ylabel(d)
|
|
24
|
+
legend()
|
|
25
|
+
grid(True)
|
|
26
|
+
|
|
27
|
+
show()
|
|
28
|
+
|
|
29
|
+
# 如果你想让函数返回图表对象以便进一步操作,可以改为:
|
|
30
|
+
# return plt.gcf(), plt.gca()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# paint/heatmap.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def heatmap(data=None, row_labels=None, col_labels=None,
|
|
7
|
+
title="Heatmap", cmap='viridis', annotate=True,
|
|
8
|
+
fmt='.2f', cbar=True, square=False):
|
|
9
|
+
"""
|
|
10
|
+
绘制热力图
|
|
11
|
+
|
|
12
|
+
参数:
|
|
13
|
+
data: 二维数据数组
|
|
14
|
+
row_labels: 行标签
|
|
15
|
+
col_labels: 列标签
|
|
16
|
+
title: 图表标题
|
|
17
|
+
cmap: 颜色映射
|
|
18
|
+
annotate: 是否显示数值
|
|
19
|
+
fmt: 数值格式
|
|
20
|
+
cbar: 是否显示颜色条
|
|
21
|
+
square: 是否保持方形
|
|
22
|
+
"""
|
|
23
|
+
fig, ax = plt.subplots(figsize=(10, 8))
|
|
24
|
+
|
|
25
|
+
# 生成默认数据
|
|
26
|
+
if data is None:
|
|
27
|
+
np.random.seed(42)
|
|
28
|
+
data = np.random.rand(8, 10)
|
|
29
|
+
row_labels = [f'Row {i + 1}' for i in range(8)]
|
|
30
|
+
col_labels = [f'Col {i + 1}' for i in range(10)]
|
|
31
|
+
|
|
32
|
+
# 绘制热力图
|
|
33
|
+
im = ax.imshow(data, cmap=cmap, aspect='auto' if not square else 'equal')
|
|
34
|
+
|
|
35
|
+
# 添加数值标签
|
|
36
|
+
if annotate:
|
|
37
|
+
for i in range(data.shape[0]):
|
|
38
|
+
for j in range(data.shape[1]):
|
|
39
|
+
text = ax.text(j, i, format(data[i, j], fmt),
|
|
40
|
+
ha="center", va="center",
|
|
41
|
+
color="white" if data[i, j] > 0.6 else "black",
|
|
42
|
+
fontsize=8)
|
|
43
|
+
|
|
44
|
+
# 设置刻度标签
|
|
45
|
+
if row_labels is not None:
|
|
46
|
+
ax.set_yticks(np.arange(data.shape[0]))
|
|
47
|
+
ax.set_yticklabels(row_labels)
|
|
48
|
+
if col_labels is not None:
|
|
49
|
+
ax.set_xticks(np.arange(data.shape[1]))
|
|
50
|
+
ax.set_xticklabels(col_labels, rotation=45, ha='right')
|
|
51
|
+
|
|
52
|
+
# 设置标题
|
|
53
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
54
|
+
|
|
55
|
+
# 添加颜色条
|
|
56
|
+
if cbar:
|
|
57
|
+
fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
|
|
58
|
+
|
|
59
|
+
plt.tight_layout()
|
|
60
|
+
return fig, ax, im
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# paint/histogram.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def histogram(data=None, bins=10, title="Histogram",
|
|
7
|
+
xlabel="Value", ylabel="Frequency",
|
|
8
|
+
color='skyblue', edgecolor='black',
|
|
9
|
+
density=False, cumulative=False,
|
|
10
|
+
show_mean=False, show_median=False):
|
|
11
|
+
"""
|
|
12
|
+
绘制直方图
|
|
13
|
+
|
|
14
|
+
参数:
|
|
15
|
+
data: 数据数组
|
|
16
|
+
bins: 柱子数量或边界
|
|
17
|
+
title: 图表标题
|
|
18
|
+
xlabel: X轴标签
|
|
19
|
+
ylabel: Y轴标签
|
|
20
|
+
color: 柱子颜色
|
|
21
|
+
edgecolor: 边框颜色
|
|
22
|
+
density: 是否显示密度
|
|
23
|
+
cumulative: 是否累积
|
|
24
|
+
show_mean: 是否显示均值线
|
|
25
|
+
show_median: 是否显示中位数线
|
|
26
|
+
"""
|
|
27
|
+
fig, ax = plt.subplots(figsize=(10, 6))
|
|
28
|
+
|
|
29
|
+
# 生成默认数据
|
|
30
|
+
if data is None:
|
|
31
|
+
np.random.seed(42)
|
|
32
|
+
data = np.random.normal(0, 1, 1000)
|
|
33
|
+
|
|
34
|
+
# 绘制直方图
|
|
35
|
+
n, bins, patches = ax.hist(data, bins=bins,
|
|
36
|
+
color=color, edgecolor=edgecolor,
|
|
37
|
+
alpha=0.7, density=density,
|
|
38
|
+
cumulative=cumulative)
|
|
39
|
+
|
|
40
|
+
# 计算统计量
|
|
41
|
+
mean_val = np.mean(data)
|
|
42
|
+
median_val = np.median(data)
|
|
43
|
+
std_val = np.std(data)
|
|
44
|
+
|
|
45
|
+
# 添加统计线
|
|
46
|
+
if show_mean:
|
|
47
|
+
ax.axvline(mean_val, color='red', linestyle='--',
|
|
48
|
+
linewidth=2, label=f'Mean: {mean_val:.2f}')
|
|
49
|
+
|
|
50
|
+
if show_median:
|
|
51
|
+
ax.axvline(median_val, color='green', linestyle='-.',
|
|
52
|
+
linewidth=2, label=f'Median: {median_val:.2f}')
|
|
53
|
+
|
|
54
|
+
# 添加正态分布曲线(如果适用)
|
|
55
|
+
if density and not cumulative:
|
|
56
|
+
from scipy.stats import norm
|
|
57
|
+
xmin, xmax = ax.get_xlim()
|
|
58
|
+
x = np.linspace(xmin, xmax, 100)
|
|
59
|
+
p = norm.pdf(x, mean_val, std_val)
|
|
60
|
+
ax.plot(x, p, 'k', linewidth=2, label='Normal Distribution')
|
|
61
|
+
|
|
62
|
+
# 设置图表属性
|
|
63
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
64
|
+
ax.set_xlabel(xlabel, fontsize=12)
|
|
65
|
+
ax.set_ylabel('Density' if density else 'Frequency', fontsize=12)
|
|
66
|
+
|
|
67
|
+
ax.grid(True, linestyle='--', alpha=0.3)
|
|
68
|
+
|
|
69
|
+
if show_mean or show_median:
|
|
70
|
+
ax.legend(fontsize=10)
|
|
71
|
+
|
|
72
|
+
# 添加统计信息文本框
|
|
73
|
+
textstr = f'N = {len(data)}\nMean = {mean_val:.2f}\nStd = {std_val:.2f}'
|
|
74
|
+
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
|
|
75
|
+
ax.text(0.02, 0.98, textstr, transform=ax.transAxes, fontsize=10,
|
|
76
|
+
verticalalignment='top', bbox=props)
|
|
77
|
+
|
|
78
|
+
plt.tight_layout()
|
|
79
|
+
return fig, ax, (n, bins, patches)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# paint/line_plot.py
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def line_plot(x_data=None, y_data_list=None, labels=None,
|
|
7
|
+
title="Line Plot", xlabel="X", ylabel="Y",
|
|
8
|
+
line_styles=None, colors=None, marker_styles=None,
|
|
9
|
+
grid=True, legend=True):
|
|
10
|
+
"""
|
|
11
|
+
绘制折线图
|
|
12
|
+
|
|
13
|
+
参数:
|
|
14
|
+
x_data: X轴数据
|
|
15
|
+
y_data_list: Y轴数据列表(多条线)
|
|
16
|
+
labels: 图例标签
|
|
17
|
+
title: 图表标题
|
|
18
|
+
xlabel: X轴标签
|
|
19
|
+
ylabel: Y轴标签
|
|
20
|
+
line_styles: 线条样式列表
|
|
21
|
+
colors: 颜色列表
|
|
22
|
+
marker_styles: 标记样式列表
|
|
23
|
+
grid: 是否显示网格
|
|
24
|
+
legend: 是否显示图例
|
|
25
|
+
"""
|
|
26
|
+
fig, ax = plt.subplots(figsize=(10, 6))
|
|
27
|
+
|
|
28
|
+
# 默认数据
|
|
29
|
+
if x_data is None:
|
|
30
|
+
x_data = np.arange(1, 11)
|
|
31
|
+
if y_data_list is None:
|
|
32
|
+
y_data_list = [np.sin(x_data), np.cos(x_data), np.tan(x_data) / 10]
|
|
33
|
+
labels = ['sin(x)', 'cos(x)', 'tan(x)/10']
|
|
34
|
+
|
|
35
|
+
# 设置默认样式
|
|
36
|
+
if colors is None:
|
|
37
|
+
colors = plt.cm.Set1(np.linspace(0, 1, len(y_data_list)))
|
|
38
|
+
if line_styles is None:
|
|
39
|
+
line_styles = ['-', '--', '-.', ':'] * (len(y_data_list) // 4 + 1)
|
|
40
|
+
if marker_styles is None:
|
|
41
|
+
marker_styles = ['o', 's', '^', 'D', 'v'] * (len(y_data_list) // 5 + 1)
|
|
42
|
+
if labels is None:
|
|
43
|
+
labels = [f'Line {i + 1}' for i in range(len(y_data_list))]
|
|
44
|
+
|
|
45
|
+
# 绘制每条线
|
|
46
|
+
lines = []
|
|
47
|
+
for i, y_data in enumerate(y_data_list):
|
|
48
|
+
line, = ax.plot(x_data, y_data,
|
|
49
|
+
linestyle=line_styles[i % len(line_styles)],
|
|
50
|
+
color=colors[i % len(colors)],
|
|
51
|
+
marker=marker_styles[i % len(marker_styles)],
|
|
52
|
+
markersize=8,
|
|
53
|
+
linewidth=2,
|
|
54
|
+
label=labels[i],
|
|
55
|
+
alpha=0.8)
|
|
56
|
+
lines.append(line)
|
|
57
|
+
|
|
58
|
+
# 设置图表属性
|
|
59
|
+
ax.set_title(title, fontsize=14, fontweight='bold', pad=20)
|
|
60
|
+
ax.set_xlabel(xlabel, fontsize=12)
|
|
61
|
+
ax.set_ylabel(ylabel, fontsize=12)
|
|
62
|
+
|
|
63
|
+
if grid:
|
|
64
|
+
ax.grid(True, linestyle='--', alpha=0.5)
|
|
65
|
+
|
|
66
|
+
if legend and len(y_data_list) > 1:
|
|
67
|
+
ax.legend(fontsize=10, loc='best')
|
|
68
|
+
|
|
69
|
+
plt.tight_layout()
|
|
70
|
+
return fig, ax, lines
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from matplotlib.pyplot import *
|
|
2
|
+
from numpy import *
|
|
3
|
+
#Import required modules
|
|
4
|
+
|
|
5
|
+
def pie_chart(a,b,c,d,e,f,g,h,i,j,k,l):
|
|
6
|
+
#Draw a pie chart
|
|
7
|
+
labels = a,b,c,d,e,f
|
|
8
|
+
sizes = [g,h,i,j,k,l]
|
|
9
|
+
colors = ['green','blue','red','yellow','purple','orange']
|
|
10
|
+
pie(sizes, labels=labels, colors= colors, autopct ='%1.1f%%', shadow=True, startangle=90)
|
|
11
|
+
axis('equal')
|
|
12
|
+
show()
|
|
13
|
+
def bar_chart(a,b,c,d,e,f):
|
|
14
|
+
#Draw a bar chart
|
|
15
|
+
n = 6
|
|
16
|
+
y = [a,b,c,d,e]
|
|
17
|
+
index = arange(n)
|
|
18
|
+
bar(left = index, height= y, cocor = f, )
|
|
19
|
+
def curve_statistical_chart(a,b,c,d):
|
|
20
|
+
# Draw a curve statistical chart
|
|
21
|
+
x = linspace(0,3 * np.pi ,a )
|
|
22
|
+
y1,y2 = sin(x),cos(x)
|
|
23
|
+
plot(x, y1)
|
|
24
|
+
plot(x, y2)
|
|
25
|
+
title(b)
|
|
26
|
+
xlabel(c)
|
|
27
|
+
ylabel(d)
|
|
28
|
+
show()
|
|
29
|
+
def scatter_plot(a,b,c,d,e,f,g,h):
|
|
30
|
+
#Draw a scatter plot
|
|
31
|
+
higth = [a,b,c,d]
|
|
32
|
+
weiggt= [e,f,g,h]
|
|
33
|
+
scatter(higth,weiggt)
|