cm-chart 1.0.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.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: cm_chart
3
+ Version: 1.0.0
4
+ Summary: 计算概论C课程中文图表快捷输出工具
5
+ Author: Chen Mo
6
+ Author-email: chenmoemail@126.com
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Natural Language :: Chinese (Simplified)
11
+ Classifier: Intended Audience :: Education
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: matplotlib>=3.5
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # cm_chart
25
+
26
+ 中文图表快捷输出工具。它不替代 `matplotlib`,而是帮学生先解决中文字体、常见图表和保存图片。
27
+
28
+ ```bash
29
+ pip install cm_chart
30
+ ```
31
+
32
+ ```python
33
+ import cm_chart
34
+
35
+ fig, ax = cm_chart.bar(['苹果', '香蕉', '梨'], [12, 8, 15], title='水果销量')
36
+ cm_chart.save(fig, '水果销量.png')
37
+ ```
38
+
39
+ 所有画图函数都会返回 `fig, ax`,学生可以继续用原生 `matplotlib` 修改细节。
@@ -0,0 +1,16 @@
1
+ # cm_chart
2
+
3
+ 中文图表快捷输出工具。它不替代 `matplotlib`,而是帮学生先解决中文字体、常见图表和保存图片。
4
+
5
+ ```bash
6
+ pip install cm_chart
7
+ ```
8
+
9
+ ```python
10
+ import cm_chart
11
+
12
+ fig, ax = cm_chart.bar(['苹果', '香蕉', '梨'], [12, 8, 15], title='水果销量')
13
+ cm_chart.save(fig, '水果销量.png')
14
+ ```
15
+
16
+ 所有画图函数都会返回 `fig, ax`,学生可以继续用原生 `matplotlib` 修改细节。
@@ -0,0 +1,6 @@
1
+ """cm_chart - 中文图表快捷输出工具。"""
2
+
3
+ from .core import setup_chinese_font, bar, line, pie, wordfreq_bar, grade_distribution, save
4
+
5
+ __version__ = '1.0.0'
6
+ __all__ = ['setup_chinese_font', 'bar', 'line', 'pie', 'wordfreq_bar', 'grade_distribution', 'save']
@@ -0,0 +1,89 @@
1
+ from collections import Counter
2
+
3
+
4
+ def _plt():
5
+ import matplotlib.pyplot as plt
6
+ setup_chinese_font()
7
+ return plt
8
+
9
+
10
+ def setup_chinese_font():
11
+ """尽量设置常见中文字体,减少中文乱码。"""
12
+ import matplotlib.pyplot as plt
13
+ plt.rcParams['font.sans-serif'] = [
14
+ 'Arial Unicode MS',
15
+ 'SimHei',
16
+ 'Microsoft YaHei',
17
+ 'Noto Sans CJK SC',
18
+ 'PingFang SC',
19
+ 'Heiti SC',
20
+ ]
21
+ plt.rcParams['axes.unicode_minus'] = False
22
+
23
+
24
+ def bar(labels, values, title='', xlabel='', ylabel='', color='#4C78A8'):
25
+ """画柱状图,返回 fig, ax。"""
26
+ plt = _plt()
27
+ fig, ax = plt.subplots(figsize=(8, 4.5))
28
+ ax.bar(labels, values, color=color)
29
+ ax.set_title(title)
30
+ ax.set_xlabel(xlabel)
31
+ ax.set_ylabel(ylabel)
32
+ fig.tight_layout()
33
+ return fig, ax
34
+
35
+
36
+ def line(x, y, title='', xlabel='', ylabel='', color='#F58518', marker='o'):
37
+ """画折线图,返回 fig, ax。"""
38
+ plt = _plt()
39
+ fig, ax = plt.subplots(figsize=(8, 4.5))
40
+ ax.plot(x, y, color=color, marker=marker)
41
+ ax.set_title(title)
42
+ ax.set_xlabel(xlabel)
43
+ ax.set_ylabel(ylabel)
44
+ fig.tight_layout()
45
+ return fig, ax
46
+
47
+
48
+ def pie(labels, values, title=''):
49
+ """画饼图,返回 fig, ax。"""
50
+ plt = _plt()
51
+ fig, ax = plt.subplots(figsize=(6, 6))
52
+ ax.pie(values, labels=labels, autopct='%1.1f%%')
53
+ ax.set_title(title)
54
+ fig.tight_layout()
55
+ return fig, ax
56
+
57
+
58
+ def wordfreq_bar(wordfreq, n=20, title='词频统计'):
59
+ """画词频柱状图。wordfreq 可以是字典或 [(词, 次数), ...]。"""
60
+ items = wordfreq.items() if isinstance(wordfreq, dict) else wordfreq
61
+ top = sorted(items, key=lambda item: item[1], reverse=True)[:n]
62
+ labels = [item[0] for item in top]
63
+ values = [item[1] for item in top]
64
+ return bar(labels, values, title=title, xlabel='词语', ylabel='次数')
65
+
66
+
67
+ def grade_distribution(scores, title='成绩分布'):
68
+ """画成绩分布柱状图。"""
69
+ bands = Counter()
70
+ for score in scores:
71
+ score = float(score)
72
+ if score >= 90:
73
+ bands['90-100'] += 1
74
+ elif score >= 80:
75
+ bands['80-89'] += 1
76
+ elif score >= 70:
77
+ bands['70-79'] += 1
78
+ elif score >= 60:
79
+ bands['60-69'] += 1
80
+ else:
81
+ bands['0-59'] += 1
82
+ labels = ['90-100', '80-89', '70-79', '60-69', '0-59']
83
+ return bar(labels, [bands[label] for label in labels], title=title, xlabel='分数段', ylabel='人数')
84
+
85
+
86
+ def save(fig, filename, dpi=160):
87
+ """保存图片并返回文件名。"""
88
+ fig.savefig(filename, dpi=dpi, bbox_inches='tight')
89
+ return filename
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: cm_chart
3
+ Version: 1.0.0
4
+ Summary: 计算概论C课程中文图表快捷输出工具
5
+ Author: Chen Mo
6
+ Author-email: chenmoemail@126.com
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Natural Language :: Chinese (Simplified)
11
+ Classifier: Intended Audience :: Education
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: matplotlib>=3.5
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # cm_chart
25
+
26
+ 中文图表快捷输出工具。它不替代 `matplotlib`,而是帮学生先解决中文字体、常见图表和保存图片。
27
+
28
+ ```bash
29
+ pip install cm_chart
30
+ ```
31
+
32
+ ```python
33
+ import cm_chart
34
+
35
+ fig, ax = cm_chart.bar(['苹果', '香蕉', '梨'], [12, 8, 15], title='水果销量')
36
+ cm_chart.save(fig, '水果销量.png')
37
+ ```
38
+
39
+ 所有画图函数都会返回 `fig, ax`,学生可以继续用原生 `matplotlib` 修改细节。
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ cm_chart/__init__.py
4
+ cm_chart/core.py
5
+ cm_chart.egg-info/PKG-INFO
6
+ cm_chart.egg-info/SOURCES.txt
7
+ cm_chart.egg-info/dependency_links.txt
8
+ cm_chart.egg-info/requires.txt
9
+ cm_chart.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ matplotlib>=3.5
@@ -0,0 +1 @@
1
+ cm_chart
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='cm_chart',
5
+ version='1.0.0',
6
+ author='Chen Mo',
7
+ author_email='chenmoemail@126.com',
8
+ description='计算概论C课程中文图表快捷输出工具',
9
+ long_description=open('README.md', encoding='utf-8').read(),
10
+ long_description_content_type='text/markdown',
11
+ packages=find_packages(),
12
+ install_requires=['matplotlib>=3.5'],
13
+ python_requires='>=3.8',
14
+ classifiers=[
15
+ 'Programming Language :: Python :: 3',
16
+ 'License :: OSI Approved :: MIT License',
17
+ 'Operating System :: OS Independent',
18
+ 'Natural Language :: Chinese (Simplified)',
19
+ 'Intended Audience :: Education',
20
+ ],
21
+ )