arabic-sciplot 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.
- arabic_sciplot-0.1.0/LICENSE +23 -0
- arabic_sciplot-0.1.0/PKG-INFO +129 -0
- arabic_sciplot-0.1.0/README.md +106 -0
- arabic_sciplot-0.1.0/pyproject.toml +31 -0
- arabic_sciplot-0.1.0/setup.cfg +4 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot/__init__.py +20 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot/matplotlib.py +98 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot/text.py +3 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot/ticks.py +62 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot.egg-info/PKG-INFO +129 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot.egg-info/SOURCES.txt +13 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot.egg-info/dependency_links.txt +1 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot.egg-info/requires.txt +10 -0
- arabic_sciplot-0.1.0/src/arabic_sciplot.egg-info/top_level.txt +1 -0
- arabic_sciplot-0.1.0/tests/test_core.py +45 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
ملخص بالعربية (للتوضيح فقط): هذه البرمجية متاحة بموجب رخصة MIT، التي تسمح بالاستخدام والتعديل والتوزيع مع الإبقاء على إشعار حقوق النشر ونص الرخصة. النص الإنجليزي التالي هو النص القانوني المعتمد.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 El Ghali Asri
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arabic-sciplot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: أدوات عربية خفيفة لتنسيق الرسوم البيانية العلمية
|
|
5
|
+
Author: El Ghali Asri
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/Pontmousse/arabic-sciplot
|
|
8
|
+
Project-URL: Issues, https://github.com/Pontmousse/arabic-sciplot/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=1.26
|
|
15
|
+
Requires-Dist: matplotlib>=3.11
|
|
16
|
+
Provides-Extra: plotly
|
|
17
|
+
Requires-Dist: plotly>=5; extra == "plotly"
|
|
18
|
+
Provides-Extra: examples
|
|
19
|
+
Requires-Dist: plotly>=5; extra == "examples"
|
|
20
|
+
Requires-Dist: scipy>=1.13; extra == "examples"
|
|
21
|
+
Requires-Dist: pillow>=10; extra == "examples"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Arabic SciPlot — الرسم العلمي بالعربية
|
|
25
|
+
|
|
26
|
+
حزمة صغيرة لتنسيق عناوين الرسوم البيانية ومحاورها وتدريجاتها بالعربية باستخدام **Matplotlib**، مع أدوات رقمية يمكن استعمالها في **Plotly**.
|
|
27
|
+
|
|
28
|
+
## التثبيت
|
|
29
|
+
|
|
30
|
+
يتطلب الإصدار `0.1.0` بايثون 3.11 أو أحدث وMatplotlib 3.11 أو أحدث.
|
|
31
|
+
|
|
32
|
+
بعد نشر الحزمة في PyPI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install arabic-sciplot
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
للتجربة من المستودع قبل النشر:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install -e .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
ولتشغيل أمثلة Plotly وB-spline الاختيارية: `pip install -e ".[examples]"`.
|
|
45
|
+
|
|
46
|
+
## الاستعمال
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import numpy as np
|
|
50
|
+
import matplotlib.pyplot as plt
|
|
51
|
+
from arabic_sciplot import arab, arabic_2d_axis_formatter
|
|
52
|
+
|
|
53
|
+
x = np.linspace(-5, 5, 200)
|
|
54
|
+
fig, ax = plt.subplots()
|
|
55
|
+
ax.plot(x, x**2)
|
|
56
|
+
ax.set_title(arab("تمثيل دالة تربيعية"))
|
|
57
|
+
arabic_2d_axis_formatter(ax)
|
|
58
|
+
plt.show()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
التوابع المتاحة: `arab`، `custom_formatter`، `custom_log_formatter`، `pi_formatter`، `generate_tickvals_and_text`، `arabic_2d_axis_formatter`، `arabic_3d_axis_formatter`، و`arabic_3d_plot_formatter`.
|
|
62
|
+
|
|
63
|
+
يمكن تعطيل قلب المحور أو تعديل نمط التدريجات من غير تغيير الإعدادات الافتراضية القديمة:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
arabic_2d_axis_formatter(ax, invert_x=False, y_on_right=False,
|
|
67
|
+
tick_direction="out", tick_length=4, tick_labelsize=12)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### مثال ثلاثي الأبعاد (Matplotlib)
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import numpy as np
|
|
74
|
+
import matplotlib.pyplot as plt
|
|
75
|
+
from arabic_sciplot import arabic_3d_axis_formatter
|
|
76
|
+
|
|
77
|
+
t = np.linspace(0, 4 * np.pi, 300)
|
|
78
|
+
fig = plt.figure()
|
|
79
|
+
ax = fig.add_subplot(111, projection="3d")
|
|
80
|
+
ax.plot(np.cos(t), np.sin(t), t)
|
|
81
|
+
arabic_3d_axis_formatter(ax)
|
|
82
|
+
ax.set_title("منحنى حلزوني ثلاثي الأبعاد")
|
|
83
|
+
plt.show()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### مثال تدريجات رياضية (Plotly — تبعية اختيارية)
|
|
87
|
+
|
|
88
|
+
للتشغيل: `pip install "arabic-sciplot[plotly]"` بعد نشر الحزمة، أو `pip install -e ".[plotly]"` من المستودع.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import numpy as np
|
|
92
|
+
import plotly.graph_objects as go
|
|
93
|
+
from arabic_sciplot import generate_tickvals_and_text
|
|
94
|
+
|
|
95
|
+
x = np.linspace(-np.pi, np.pi, 100)
|
|
96
|
+
tickvals, ticktext = generate_tickvals_and_text(
|
|
97
|
+
x, num_ticks=5, use_pi_format=True
|
|
98
|
+
)
|
|
99
|
+
fig = go.Figure()
|
|
100
|
+
fig.add_scatter(x=x, y=np.sin(x))
|
|
101
|
+
fig.update_xaxes(title="س", tickvals=tickvals, ticktext=ticktext)
|
|
102
|
+
fig.show()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## اتجاه الكتابة والخطوط
|
|
106
|
+
|
|
107
|
+
أضاف **Matplotlib 3.11** دعم تشكيل الحروف العربية وترتيب الكتابة من اليمين إلى اليسار. لذلك يعيد `arab(text)` النص نفسه دون تغييره، ولم نعد نستخدم `arabic-reshaper` أو `python-bidi`. **لا تُمرّر نصًا مُعاد تشكيله مسبقًا** إلى Matplotlib الجديد؛ فقد ينعكس ترتيبه مرتين.
|
|
108
|
+
|
|
109
|
+
يجب توفر خط يدعم المحارف المطلوبة، مثل **DejaVu Sans** للحروف الشائعة، أو **Amiri** أو **Noto Naskh Arabic** لبعض النصوص والتشكيل. لا تُضمّن الحزمة خطوطًا ولا تفرض خطًا على المستخدم. يمكن تعيين خط مثبت لديك عبر `plt.rcParams["font.family"] = "Amiri"`. يعتمد العرض النهائي على الخط ومحرك الرسم.
|
|
110
|
+
|
|
111
|
+
تُبقي الدوال الإعدادات القديمة للمحاور: قلب المحور السيني، ونقل تدريجات الصادات إلى اليمين في الرسم الثنائي، وقلب المحورين الأفقيين في الرسم الثلاثي.
|
|
112
|
+
|
|
113
|
+
## أمثلة
|
|
114
|
+
|
|
115
|
+
- [`examples/basic_2d.py`](examples/basic_2d.py) — رسم علمي ثنائي الأبعاد.
|
|
116
|
+
- [`examples/plot_3d.py`](examples/plot_3d.py) — رسم حلزوني ثلاثي الأبعاد.
|
|
117
|
+
- [`examples/plotly_ticks.py`](examples/plotly_ticks.py) — تدريجات رياضية عربية في Plotly (إضافي).
|
|
118
|
+
- [`examples/vector_field.py`](examples/vector_field.py) — حقل متجهات مأخوذ من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/calculus/vector_calculus/curl2d.py).
|
|
119
|
+
- [`examples/spline_animation.py`](examples/spline_animation.py) — منحنى B-spline متحرك من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/geometry/splines/bsplines/bspline.py)؛ ينشئ ملف GIF ويحتاج SciPy وPillow.
|
|
120
|
+
|
|
121
|
+
## الترخيص
|
|
122
|
+
|
|
123
|
+
MIT — انظر `LICENSE`.
|
|
124
|
+
|
|
125
|
+
## للمطورين ووكلاء الذكاء الاصطناعي
|
|
126
|
+
|
|
127
|
+
- [خارطة التطوير وتغطية أنواع الرسوم](docs/ROADMAP.md).
|
|
128
|
+
- [دليل الوكيل لإنشاء الرسوم العلمية بالعربية](docs/AI_AGENT_GUIDE.md).
|
|
129
|
+
- [تعليمات مختصرة لوكلاء البرمجة](AGENTS.md).
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Arabic SciPlot — الرسم العلمي بالعربية
|
|
2
|
+
|
|
3
|
+
حزمة صغيرة لتنسيق عناوين الرسوم البيانية ومحاورها وتدريجاتها بالعربية باستخدام **Matplotlib**، مع أدوات رقمية يمكن استعمالها في **Plotly**.
|
|
4
|
+
|
|
5
|
+
## التثبيت
|
|
6
|
+
|
|
7
|
+
يتطلب الإصدار `0.1.0` بايثون 3.11 أو أحدث وMatplotlib 3.11 أو أحدث.
|
|
8
|
+
|
|
9
|
+
بعد نشر الحزمة في PyPI:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install arabic-sciplot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
للتجربة من المستودع قبل النشر:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install -e .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
ولتشغيل أمثلة Plotly وB-spline الاختيارية: `pip install -e ".[examples]"`.
|
|
22
|
+
|
|
23
|
+
## الاستعمال
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import numpy as np
|
|
27
|
+
import matplotlib.pyplot as plt
|
|
28
|
+
from arabic_sciplot import arab, arabic_2d_axis_formatter
|
|
29
|
+
|
|
30
|
+
x = np.linspace(-5, 5, 200)
|
|
31
|
+
fig, ax = plt.subplots()
|
|
32
|
+
ax.plot(x, x**2)
|
|
33
|
+
ax.set_title(arab("تمثيل دالة تربيعية"))
|
|
34
|
+
arabic_2d_axis_formatter(ax)
|
|
35
|
+
plt.show()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
التوابع المتاحة: `arab`، `custom_formatter`، `custom_log_formatter`، `pi_formatter`، `generate_tickvals_and_text`، `arabic_2d_axis_formatter`، `arabic_3d_axis_formatter`، و`arabic_3d_plot_formatter`.
|
|
39
|
+
|
|
40
|
+
يمكن تعطيل قلب المحور أو تعديل نمط التدريجات من غير تغيير الإعدادات الافتراضية القديمة:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
arabic_2d_axis_formatter(ax, invert_x=False, y_on_right=False,
|
|
44
|
+
tick_direction="out", tick_length=4, tick_labelsize=12)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### مثال ثلاثي الأبعاد (Matplotlib)
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import numpy as np
|
|
51
|
+
import matplotlib.pyplot as plt
|
|
52
|
+
from arabic_sciplot import arabic_3d_axis_formatter
|
|
53
|
+
|
|
54
|
+
t = np.linspace(0, 4 * np.pi, 300)
|
|
55
|
+
fig = plt.figure()
|
|
56
|
+
ax = fig.add_subplot(111, projection="3d")
|
|
57
|
+
ax.plot(np.cos(t), np.sin(t), t)
|
|
58
|
+
arabic_3d_axis_formatter(ax)
|
|
59
|
+
ax.set_title("منحنى حلزوني ثلاثي الأبعاد")
|
|
60
|
+
plt.show()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### مثال تدريجات رياضية (Plotly — تبعية اختيارية)
|
|
64
|
+
|
|
65
|
+
للتشغيل: `pip install "arabic-sciplot[plotly]"` بعد نشر الحزمة، أو `pip install -e ".[plotly]"` من المستودع.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import numpy as np
|
|
69
|
+
import plotly.graph_objects as go
|
|
70
|
+
from arabic_sciplot import generate_tickvals_and_text
|
|
71
|
+
|
|
72
|
+
x = np.linspace(-np.pi, np.pi, 100)
|
|
73
|
+
tickvals, ticktext = generate_tickvals_and_text(
|
|
74
|
+
x, num_ticks=5, use_pi_format=True
|
|
75
|
+
)
|
|
76
|
+
fig = go.Figure()
|
|
77
|
+
fig.add_scatter(x=x, y=np.sin(x))
|
|
78
|
+
fig.update_xaxes(title="س", tickvals=tickvals, ticktext=ticktext)
|
|
79
|
+
fig.show()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## اتجاه الكتابة والخطوط
|
|
83
|
+
|
|
84
|
+
أضاف **Matplotlib 3.11** دعم تشكيل الحروف العربية وترتيب الكتابة من اليمين إلى اليسار. لذلك يعيد `arab(text)` النص نفسه دون تغييره، ولم نعد نستخدم `arabic-reshaper` أو `python-bidi`. **لا تُمرّر نصًا مُعاد تشكيله مسبقًا** إلى Matplotlib الجديد؛ فقد ينعكس ترتيبه مرتين.
|
|
85
|
+
|
|
86
|
+
يجب توفر خط يدعم المحارف المطلوبة، مثل **DejaVu Sans** للحروف الشائعة، أو **Amiri** أو **Noto Naskh Arabic** لبعض النصوص والتشكيل. لا تُضمّن الحزمة خطوطًا ولا تفرض خطًا على المستخدم. يمكن تعيين خط مثبت لديك عبر `plt.rcParams["font.family"] = "Amiri"`. يعتمد العرض النهائي على الخط ومحرك الرسم.
|
|
87
|
+
|
|
88
|
+
تُبقي الدوال الإعدادات القديمة للمحاور: قلب المحور السيني، ونقل تدريجات الصادات إلى اليمين في الرسم الثنائي، وقلب المحورين الأفقيين في الرسم الثلاثي.
|
|
89
|
+
|
|
90
|
+
## أمثلة
|
|
91
|
+
|
|
92
|
+
- [`examples/basic_2d.py`](examples/basic_2d.py) — رسم علمي ثنائي الأبعاد.
|
|
93
|
+
- [`examples/plot_3d.py`](examples/plot_3d.py) — رسم حلزوني ثلاثي الأبعاد.
|
|
94
|
+
- [`examples/plotly_ticks.py`](examples/plotly_ticks.py) — تدريجات رياضية عربية في Plotly (إضافي).
|
|
95
|
+
- [`examples/vector_field.py`](examples/vector_field.py) — حقل متجهات مأخوذ من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/calculus/vector_calculus/curl2d.py).
|
|
96
|
+
- [`examples/spline_animation.py`](examples/spline_animation.py) — منحنى B-spline متحرك من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/geometry/splines/bsplines/bspline.py)؛ ينشئ ملف GIF ويحتاج SciPy وPillow.
|
|
97
|
+
|
|
98
|
+
## الترخيص
|
|
99
|
+
|
|
100
|
+
MIT — انظر `LICENSE`.
|
|
101
|
+
|
|
102
|
+
## للمطورين ووكلاء الذكاء الاصطناعي
|
|
103
|
+
|
|
104
|
+
- [خارطة التطوير وتغطية أنواع الرسوم](docs/ROADMAP.md).
|
|
105
|
+
- [دليل الوكيل لإنشاء الرسوم العلمية بالعربية](docs/AI_AGENT_GUIDE.md).
|
|
106
|
+
- [تعليمات مختصرة لوكلاء البرمجة](AGENTS.md).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "arabic-sciplot"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "أدوات عربية خفيفة لتنسيق الرسوم البيانية العلمية"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "El Ghali Asri" }]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"numpy>=1.26",
|
|
15
|
+
"matplotlib>=3.11",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
plotly = ["plotly>=5"]
|
|
24
|
+
examples = ["plotly>=5", "scipy>=1.13", "pillow>=10"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Repository = "https://github.com/Pontmousse/arabic-sciplot"
|
|
28
|
+
Issues = "https://github.com/Pontmousse/arabic-sciplot/issues"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
where = ["src"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""أدوات تنسيق الرسوم العلمية بالعربية."""
|
|
2
|
+
|
|
3
|
+
from .text import arab
|
|
4
|
+
from .ticks import (
|
|
5
|
+
custom_formatter,
|
|
6
|
+
custom_log_formatter,
|
|
7
|
+
generate_tickvals_and_text,
|
|
8
|
+
pi_formatter,
|
|
9
|
+
)
|
|
10
|
+
from .matplotlib import (
|
|
11
|
+
arabic_2d_axis_formatter,
|
|
12
|
+
arabic_3d_axis_formatter,
|
|
13
|
+
arabic_3d_plot_formatter,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"arab", "custom_formatter", "custom_log_formatter", "pi_formatter",
|
|
18
|
+
"generate_tickvals_and_text", "arabic_2d_axis_formatter",
|
|
19
|
+
"arabic_3d_axis_formatter", "arabic_3d_plot_formatter",
|
|
20
|
+
]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
from matplotlib.ticker import FuncFormatter
|
|
3
|
+
|
|
4
|
+
from .text import arab
|
|
5
|
+
from .ticks import custom_formatter, custom_log_formatter
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def arabic_2d_axis_formatter(ax, log=False, labelsize=16, *, invert_x=True, y_on_right=True,
|
|
9
|
+
tick_direction='in', tick_length=6, tick_labelsize=None):
|
|
10
|
+
if not log:
|
|
11
|
+
ax.xaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
12
|
+
ax.yaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
13
|
+
elif log:
|
|
14
|
+
ax.xaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
15
|
+
ax.yaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
16
|
+
|
|
17
|
+
# Inverse the x-axis
|
|
18
|
+
if invert_x:
|
|
19
|
+
ax.invert_xaxis()
|
|
20
|
+
else:
|
|
21
|
+
ax.xaxis.set_inverted(False)
|
|
22
|
+
|
|
23
|
+
# Move the y-axis to the right
|
|
24
|
+
if y_on_right:
|
|
25
|
+
ax.yaxis.set_label_position("right")
|
|
26
|
+
ax.yaxis.tick_right()
|
|
27
|
+
else:
|
|
28
|
+
ax.yaxis.set_label_position("left")
|
|
29
|
+
ax.yaxis.tick_left()
|
|
30
|
+
|
|
31
|
+
#set tick size
|
|
32
|
+
ax.tick_params(axis='both', which='major',
|
|
33
|
+
labelsize=labelsize-6 if tick_labelsize is None else tick_labelsize,
|
|
34
|
+
direction=tick_direction, length=tick_length)
|
|
35
|
+
|
|
36
|
+
# Set axis labels
|
|
37
|
+
ax.set_xlabel(arab('س'), fontsize=labelsize)
|
|
38
|
+
ax.set_ylabel(arab('ص'), fontsize=labelsize)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def arabic_3d_axis_formatter(ax, log=False, labelsize=16, *, invert_x=True, invert_y=True,
|
|
43
|
+
tick_direction='in', tick_length=6, tick_labelsize=None):
|
|
44
|
+
if not log:
|
|
45
|
+
ax.xaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
46
|
+
ax.yaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
47
|
+
ax.zaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
48
|
+
elif log:
|
|
49
|
+
ax.xaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
50
|
+
ax.yaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
51
|
+
ax.zaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
52
|
+
|
|
53
|
+
# Inverse the x-axis
|
|
54
|
+
if invert_x:
|
|
55
|
+
ax.invert_xaxis()
|
|
56
|
+
else:
|
|
57
|
+
ax.xaxis.set_inverted(False)
|
|
58
|
+
if invert_y:
|
|
59
|
+
ax.invert_yaxis()
|
|
60
|
+
else:
|
|
61
|
+
ax.yaxis.set_inverted(False)
|
|
62
|
+
|
|
63
|
+
# Tick font size
|
|
64
|
+
ax.tick_params(axis='both', which='major',
|
|
65
|
+
labelsize=labelsize-6 if tick_labelsize is None else tick_labelsize,
|
|
66
|
+
direction=tick_direction, length=tick_length)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Move the y-axis to the right
|
|
70
|
+
# ax.yaxis.set_label_position("right")
|
|
71
|
+
# ax.yaxis.tick_right()
|
|
72
|
+
|
|
73
|
+
# Set axis labels
|
|
74
|
+
ax.set_xlabel(arab('س'), fontsize=labelsize)
|
|
75
|
+
ax.set_ylabel(arab('ص'), fontsize=labelsize)
|
|
76
|
+
ax.set_zlabel(arab('ع'), fontsize=labelsize)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def arabic_3d_plot_formatter(log, *, invert_x=True, invert_y=True):
|
|
80
|
+
# Apply the custom formatting to the axis
|
|
81
|
+
if not log:
|
|
82
|
+
plt.gca().xaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
83
|
+
plt.gca().yaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
84
|
+
plt.gca().zaxis.set_major_formatter(FuncFormatter(custom_formatter))
|
|
85
|
+
elif log:
|
|
86
|
+
plt.gca().xaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
87
|
+
plt.gca().yaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
88
|
+
plt.gca().zaxis.set_major_formatter(FuncFormatter(custom_log_formatter))
|
|
89
|
+
|
|
90
|
+
# Flip the x-y-axis
|
|
91
|
+
if invert_x:
|
|
92
|
+
plt.gca().invert_xaxis()
|
|
93
|
+
else:
|
|
94
|
+
plt.gca().xaxis.set_inverted(False)
|
|
95
|
+
if invert_y:
|
|
96
|
+
plt.gca().invert_yaxis()
|
|
97
|
+
else:
|
|
98
|
+
plt.gca().yaxis.set_inverted(False)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def custom_log_formatter(x, pos=None):
|
|
5
|
+
"""
|
|
6
|
+
Custom formatter for log scale tick labels.
|
|
7
|
+
Formats labels as {}^{1-}10 for negative exponents and 10^{exp} for positive exponents.
|
|
8
|
+
"""
|
|
9
|
+
if x == 0:
|
|
10
|
+
return "0" # Avoid log(0) issues
|
|
11
|
+
|
|
12
|
+
exponent = int(np.log10(x)) # Get log base-10 exponent
|
|
13
|
+
|
|
14
|
+
if exponent < 0:
|
|
15
|
+
return rf"$^{{{abs(exponent)}\!\!-\!\!}}10$" # Example: 10^{1-}, 10^{2-}
|
|
16
|
+
else:
|
|
17
|
+
return rf"$^{{{exponent}}}10$" # Example: 10^1, 10^2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def custom_formatter(x, pos=None):
|
|
21
|
+
if x < 0:
|
|
22
|
+
return f'{abs(x):.2f}-' # Format to 2 decimal places
|
|
23
|
+
return f'{x:.2f}' # Format to 2 decimal places
|
|
24
|
+
|
|
25
|
+
def pi_formatter(x):
|
|
26
|
+
"""Formats axis labels as multiples of π using fractions where necessary."""
|
|
27
|
+
from fractions import Fraction
|
|
28
|
+
sign = ""
|
|
29
|
+
if x<0: sign = "-"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
pi_fraction = Fraction(x / np.pi).limit_denominator()
|
|
33
|
+
|
|
34
|
+
if pi_fraction.denominator == 1: # If it's an integer
|
|
35
|
+
if pi_fraction.numerator == 0:
|
|
36
|
+
return '0'
|
|
37
|
+
elif pi_fraction.numerator == 1:
|
|
38
|
+
return 'ط'
|
|
39
|
+
elif pi_fraction.numerator == -1:
|
|
40
|
+
return 'ط-'
|
|
41
|
+
else:
|
|
42
|
+
text = "\u0637" + str(abs(pi_fraction.numerator)) + sign
|
|
43
|
+
return text
|
|
44
|
+
return f'ط{pi_fraction.denominator}\\{abs(pi_fraction.numerator)}'+ sign
|
|
45
|
+
|
|
46
|
+
def generate_tickvals_and_text(data, num_ticks=4, use_pi_format=False, minmax = None):
|
|
47
|
+
"""Generates evenly spaced tick values and formatted tick text for an axis."""
|
|
48
|
+
|
|
49
|
+
if minmax == None:
|
|
50
|
+
min_val, max_val = np.min(data), np.max(data)
|
|
51
|
+
else:
|
|
52
|
+
min_val = minmax[0]
|
|
53
|
+
max_val = minmax[1]
|
|
54
|
+
|
|
55
|
+
tickvals = np.linspace(min_val, max_val, num_ticks).tolist()
|
|
56
|
+
|
|
57
|
+
if use_pi_format:
|
|
58
|
+
ticktext = [pi_formatter(x) for x in tickvals]
|
|
59
|
+
else:
|
|
60
|
+
ticktext = [custom_formatter(x) for x in tickvals]
|
|
61
|
+
|
|
62
|
+
return tickvals, ticktext
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arabic-sciplot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: أدوات عربية خفيفة لتنسيق الرسوم البيانية العلمية
|
|
5
|
+
Author: El Ghali Asri
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/Pontmousse/arabic-sciplot
|
|
8
|
+
Project-URL: Issues, https://github.com/Pontmousse/arabic-sciplot/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=1.26
|
|
15
|
+
Requires-Dist: matplotlib>=3.11
|
|
16
|
+
Provides-Extra: plotly
|
|
17
|
+
Requires-Dist: plotly>=5; extra == "plotly"
|
|
18
|
+
Provides-Extra: examples
|
|
19
|
+
Requires-Dist: plotly>=5; extra == "examples"
|
|
20
|
+
Requires-Dist: scipy>=1.13; extra == "examples"
|
|
21
|
+
Requires-Dist: pillow>=10; extra == "examples"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Arabic SciPlot — الرسم العلمي بالعربية
|
|
25
|
+
|
|
26
|
+
حزمة صغيرة لتنسيق عناوين الرسوم البيانية ومحاورها وتدريجاتها بالعربية باستخدام **Matplotlib**، مع أدوات رقمية يمكن استعمالها في **Plotly**.
|
|
27
|
+
|
|
28
|
+
## التثبيت
|
|
29
|
+
|
|
30
|
+
يتطلب الإصدار `0.1.0` بايثون 3.11 أو أحدث وMatplotlib 3.11 أو أحدث.
|
|
31
|
+
|
|
32
|
+
بعد نشر الحزمة في PyPI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install arabic-sciplot
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
للتجربة من المستودع قبل النشر:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install -e .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
ولتشغيل أمثلة Plotly وB-spline الاختيارية: `pip install -e ".[examples]"`.
|
|
45
|
+
|
|
46
|
+
## الاستعمال
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import numpy as np
|
|
50
|
+
import matplotlib.pyplot as plt
|
|
51
|
+
from arabic_sciplot import arab, arabic_2d_axis_formatter
|
|
52
|
+
|
|
53
|
+
x = np.linspace(-5, 5, 200)
|
|
54
|
+
fig, ax = plt.subplots()
|
|
55
|
+
ax.plot(x, x**2)
|
|
56
|
+
ax.set_title(arab("تمثيل دالة تربيعية"))
|
|
57
|
+
arabic_2d_axis_formatter(ax)
|
|
58
|
+
plt.show()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
التوابع المتاحة: `arab`، `custom_formatter`، `custom_log_formatter`، `pi_formatter`، `generate_tickvals_and_text`، `arabic_2d_axis_formatter`، `arabic_3d_axis_formatter`، و`arabic_3d_plot_formatter`.
|
|
62
|
+
|
|
63
|
+
يمكن تعطيل قلب المحور أو تعديل نمط التدريجات من غير تغيير الإعدادات الافتراضية القديمة:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
arabic_2d_axis_formatter(ax, invert_x=False, y_on_right=False,
|
|
67
|
+
tick_direction="out", tick_length=4, tick_labelsize=12)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### مثال ثلاثي الأبعاد (Matplotlib)
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import numpy as np
|
|
74
|
+
import matplotlib.pyplot as plt
|
|
75
|
+
from arabic_sciplot import arabic_3d_axis_formatter
|
|
76
|
+
|
|
77
|
+
t = np.linspace(0, 4 * np.pi, 300)
|
|
78
|
+
fig = plt.figure()
|
|
79
|
+
ax = fig.add_subplot(111, projection="3d")
|
|
80
|
+
ax.plot(np.cos(t), np.sin(t), t)
|
|
81
|
+
arabic_3d_axis_formatter(ax)
|
|
82
|
+
ax.set_title("منحنى حلزوني ثلاثي الأبعاد")
|
|
83
|
+
plt.show()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### مثال تدريجات رياضية (Plotly — تبعية اختيارية)
|
|
87
|
+
|
|
88
|
+
للتشغيل: `pip install "arabic-sciplot[plotly]"` بعد نشر الحزمة، أو `pip install -e ".[plotly]"` من المستودع.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import numpy as np
|
|
92
|
+
import plotly.graph_objects as go
|
|
93
|
+
from arabic_sciplot import generate_tickvals_and_text
|
|
94
|
+
|
|
95
|
+
x = np.linspace(-np.pi, np.pi, 100)
|
|
96
|
+
tickvals, ticktext = generate_tickvals_and_text(
|
|
97
|
+
x, num_ticks=5, use_pi_format=True
|
|
98
|
+
)
|
|
99
|
+
fig = go.Figure()
|
|
100
|
+
fig.add_scatter(x=x, y=np.sin(x))
|
|
101
|
+
fig.update_xaxes(title="س", tickvals=tickvals, ticktext=ticktext)
|
|
102
|
+
fig.show()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## اتجاه الكتابة والخطوط
|
|
106
|
+
|
|
107
|
+
أضاف **Matplotlib 3.11** دعم تشكيل الحروف العربية وترتيب الكتابة من اليمين إلى اليسار. لذلك يعيد `arab(text)` النص نفسه دون تغييره، ولم نعد نستخدم `arabic-reshaper` أو `python-bidi`. **لا تُمرّر نصًا مُعاد تشكيله مسبقًا** إلى Matplotlib الجديد؛ فقد ينعكس ترتيبه مرتين.
|
|
108
|
+
|
|
109
|
+
يجب توفر خط يدعم المحارف المطلوبة، مثل **DejaVu Sans** للحروف الشائعة، أو **Amiri** أو **Noto Naskh Arabic** لبعض النصوص والتشكيل. لا تُضمّن الحزمة خطوطًا ولا تفرض خطًا على المستخدم. يمكن تعيين خط مثبت لديك عبر `plt.rcParams["font.family"] = "Amiri"`. يعتمد العرض النهائي على الخط ومحرك الرسم.
|
|
110
|
+
|
|
111
|
+
تُبقي الدوال الإعدادات القديمة للمحاور: قلب المحور السيني، ونقل تدريجات الصادات إلى اليمين في الرسم الثنائي، وقلب المحورين الأفقيين في الرسم الثلاثي.
|
|
112
|
+
|
|
113
|
+
## أمثلة
|
|
114
|
+
|
|
115
|
+
- [`examples/basic_2d.py`](examples/basic_2d.py) — رسم علمي ثنائي الأبعاد.
|
|
116
|
+
- [`examples/plot_3d.py`](examples/plot_3d.py) — رسم حلزوني ثلاثي الأبعاد.
|
|
117
|
+
- [`examples/plotly_ticks.py`](examples/plotly_ticks.py) — تدريجات رياضية عربية في Plotly (إضافي).
|
|
118
|
+
- [`examples/vector_field.py`](examples/vector_field.py) — حقل متجهات مأخوذ من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/calculus/vector_calculus/curl2d.py).
|
|
119
|
+
- [`examples/spline_animation.py`](examples/spline_animation.py) — منحنى B-spline متحرك من [الموسوعة العربية](https://github.com/Pontmousse/alalbab/blob/main/resources/geometry/splines/bsplines/bspline.py)؛ ينشئ ملف GIF ويحتاج SciPy وPillow.
|
|
120
|
+
|
|
121
|
+
## الترخيص
|
|
122
|
+
|
|
123
|
+
MIT — انظر `LICENSE`.
|
|
124
|
+
|
|
125
|
+
## للمطورين ووكلاء الذكاء الاصطناعي
|
|
126
|
+
|
|
127
|
+
- [خارطة التطوير وتغطية أنواع الرسوم](docs/ROADMAP.md).
|
|
128
|
+
- [دليل الوكيل لإنشاء الرسوم العلمية بالعربية](docs/AI_AGENT_GUIDE.md).
|
|
129
|
+
- [تعليمات مختصرة لوكلاء البرمجة](AGENTS.md).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/arabic_sciplot/__init__.py
|
|
5
|
+
src/arabic_sciplot/matplotlib.py
|
|
6
|
+
src/arabic_sciplot/text.py
|
|
7
|
+
src/arabic_sciplot/ticks.py
|
|
8
|
+
src/arabic_sciplot.egg-info/PKG-INFO
|
|
9
|
+
src/arabic_sciplot.egg-info/SOURCES.txt
|
|
10
|
+
src/arabic_sciplot.egg-info/dependency_links.txt
|
|
11
|
+
src/arabic_sciplot.egg-info/requires.txt
|
|
12
|
+
src/arabic_sciplot.egg-info/top_level.txt
|
|
13
|
+
tests/test_core.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
arabic_sciplot
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import matplotlib
|
|
4
|
+
matplotlib.use("Agg")
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
|
|
7
|
+
from arabic_sciplot import (
|
|
8
|
+
arab, custom_formatter, custom_log_formatter, generate_tickvals_and_text,
|
|
9
|
+
arabic_2d_axis_formatter, arabic_3d_axis_formatter,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CoreTests(unittest.TestCase):
|
|
14
|
+
def test_native_text_and_formatters(self):
|
|
15
|
+
self.assertEqual(arab("مرحبًا"), "مرحبًا")
|
|
16
|
+
self.assertEqual(custom_formatter(-2), "2.00-")
|
|
17
|
+
self.assertEqual(custom_formatter(-2, 0), "2.00-")
|
|
18
|
+
self.assertEqual(custom_log_formatter(0), "0")
|
|
19
|
+
self.assertEqual(custom_log_formatter(10, 0), "$^{1}10$")
|
|
20
|
+
|
|
21
|
+
def test_tick_generation(self):
|
|
22
|
+
positions, labels = generate_tickvals_and_text([0, 1], num_ticks=3)
|
|
23
|
+
self.assertEqual(positions, [0, 0.5, 1])
|
|
24
|
+
self.assertEqual(labels, ["0.00", "0.50", "1.00"])
|
|
25
|
+
|
|
26
|
+
def test_configurable_axes(self):
|
|
27
|
+
fig, ax = plt.subplots()
|
|
28
|
+
arabic_2d_axis_formatter(ax)
|
|
29
|
+
self.assertTrue(ax.xaxis_inverted())
|
|
30
|
+
self.assertEqual(ax.yaxis.get_ticks_position(), "right")
|
|
31
|
+
arabic_2d_axis_formatter(ax, invert_x=False, y_on_right=False,
|
|
32
|
+
tick_direction="out", tick_length=4)
|
|
33
|
+
self.assertFalse(ax.xaxis_inverted())
|
|
34
|
+
self.assertEqual(ax.yaxis.get_ticks_position(), "left")
|
|
35
|
+
plt.close(fig)
|
|
36
|
+
fig = plt.figure()
|
|
37
|
+
ax3 = fig.add_subplot(111, projection="3d")
|
|
38
|
+
arabic_3d_axis_formatter(ax3)
|
|
39
|
+
self.assertTrue(ax3.xaxis_inverted())
|
|
40
|
+
self.assertTrue(ax3.yaxis_inverted())
|
|
41
|
+
plt.close(fig)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
unittest.main()
|