kitpylib 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.
- kitpylib-1.0.0/PKG-INFO +61 -0
- kitpylib-1.0.0/kitpylib/PyFile/__init__.py +22 -0
- kitpylib-1.0.0/kitpylib/PyFile/classes.py +35 -0
- kitpylib-1.0.0/kitpylib/PyFile/funcs.py +35 -0
- kitpylib-1.0.0/kitpylib/PyMath/__init__.py +3 -0
- kitpylib-1.0.0/kitpylib/PyMath/findroot.py +68 -0
- kitpylib-1.0.0/kitpylib/PyMath/mathfuncs.py +6 -0
- kitpylib-1.0.0/kitpylib/PyMath/spf1d.py +38 -0
- kitpylib-1.0.0/kitpylib/PyMath/spf2d.py +33 -0
- kitpylib-1.0.0/kitpylib/PyMath/spf3d.py +30 -0
- kitpylib-1.0.0/kitpylib/PyModule/__init__.py +3 -0
- kitpylib-1.0.0/kitpylib/PyModule/docstr.py +34 -0
- kitpylib-1.0.0/kitpylib/PyModule/install.py +35 -0
- kitpylib-1.0.0/kitpylib/PyModule/license.py +27 -0
- kitpylib-1.0.0/kitpylib/PyPlot/__init__.py +2 -0
- kitpylib-1.0.0/kitpylib/PyPlot/backend.py +49 -0
- kitpylib-1.0.0/kitpylib/PyPlot/funcplot.py +62 -0
- kitpylib-1.0.0/kitpylib/PyPlot/image0.png +0 -0
- kitpylib-1.0.0/kitpylib/PyPlot/image1.png +0 -0
- kitpylib-1.0.0/kitpylib/__init__.py +37 -0
- kitpylib-1.0.0/kitpylib/init.py +5 -0
- kitpylib-1.0.0/kitpylib.egg-info/PKG-INFO +61 -0
- kitpylib-1.0.0/kitpylib.egg-info/SOURCES.txt +26 -0
- kitpylib-1.0.0/kitpylib.egg-info/dependency_links.txt +1 -0
- kitpylib-1.0.0/kitpylib.egg-info/requires.txt +4 -0
- kitpylib-1.0.0/kitpylib.egg-info/top_level.txt +1 -0
- kitpylib-1.0.0/setup.cfg +4 -0
- kitpylib-1.0.0/setup.py +13 -0
kitpylib-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kitpylib
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python Library of Basic Tools
|
|
5
|
+
Author: S_My
|
|
6
|
+
Author-email: mingyang3sun@hotmail.com
|
|
7
|
+
License: MIT License(Copyright (c) 2025-2026, S_My Programming Team & KitPy Developers)
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 7
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/x-rst
|
|
15
|
+
Requires-Dist: numpy>=1.26.4
|
|
16
|
+
Requires-Dist: matplotlib>=3.9.2
|
|
17
|
+
Requires-Dist: scipy>=1.13.1
|
|
18
|
+
Requires-Dist: setuptools>=72.1.0
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
KitPyLib
|
|
31
|
+
========
|
|
32
|
+
|
|
33
|
+
A Python Library of basic tools.
|
|
34
|
+
|
|
35
|
+
How to use
|
|
36
|
+
----------
|
|
37
|
+
We recommend you to import `kitpy` as ``kp``:
|
|
38
|
+
|
|
39
|
+
>>> import kitpy as kp
|
|
40
|
+
>>> kp.fplot2d(lambda x: x**3, 0, 2)
|
|
41
|
+
|
|
42
|
+
Use the built-in ``help`` function to view a function's docstring:
|
|
43
|
+
|
|
44
|
+
>>> help(kp.fplot2d)
|
|
45
|
+
... # doctest: +SKIP
|
|
46
|
+
|
|
47
|
+
Available subpackages
|
|
48
|
+
---------------------
|
|
49
|
+
PyFile
|
|
50
|
+
KitPy's subpackage to solve txt file problems
|
|
51
|
+
PyWidget
|
|
52
|
+
KitPy's subpackage about qt widgets
|
|
53
|
+
|
|
54
|
+
Utilities
|
|
55
|
+
---------
|
|
56
|
+
__version__
|
|
57
|
+
KitPy version string
|
|
58
|
+
__copr__
|
|
59
|
+
KitPy copyright string
|
|
60
|
+
__lic__
|
|
61
|
+
KitPy license string
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'''
|
|
2
|
+
PyFile: A useful module to process files
|
|
3
|
+
========================================
|
|
4
|
+
|
|
5
|
+
How to use
|
|
6
|
+
----------
|
|
7
|
+
|
|
8
|
+
>>> import kitpy.PyFile as pf
|
|
9
|
+
|
|
10
|
+
Available functions and class
|
|
11
|
+
-----------------------------
|
|
12
|
+
This module provides functions and a class to process txt files::
|
|
13
|
+
|
|
14
|
+
exists(function): tell the user whether the txt file exists
|
|
15
|
+
makefile(function): generate a txt file
|
|
16
|
+
delfile(function): delete a txt file
|
|
17
|
+
rename(function): rename a txt file
|
|
18
|
+
File(class): `read` and `write`
|
|
19
|
+
|
|
20
|
+
See documentation for the functions and classes.'''
|
|
21
|
+
from .classes import File
|
|
22
|
+
from .funcs import exists, makefile, delfile, rename
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .funcs import exists
|
|
3
|
+
|
|
4
|
+
class File:
|
|
5
|
+
'''A class to process files.'''
|
|
6
|
+
def __init__(self, filename: str):
|
|
7
|
+
if exists(filename, msg=False):
|
|
8
|
+
self.filename = filename
|
|
9
|
+
else:
|
|
10
|
+
exists(filename)
|
|
11
|
+
|
|
12
|
+
def read_data(self, skiprows=2):
|
|
13
|
+
return np.loadtxt(self.filename, skiprows=skiprows)
|
|
14
|
+
|
|
15
|
+
def write(self, string: str):
|
|
16
|
+
with open(self.filename, 'a') as f:
|
|
17
|
+
f.write(string+'\n')
|
|
18
|
+
print(f'The file `{self.filename}` is saved successfully.')
|
|
19
|
+
|
|
20
|
+
def load_all(self):
|
|
21
|
+
with open(self.filename, 'r') as f:
|
|
22
|
+
for i in f:
|
|
23
|
+
print(i, end='')
|
|
24
|
+
|
|
25
|
+
def read_text(self, skiprows=2):
|
|
26
|
+
with open(self.filename, 'r') as f:
|
|
27
|
+
for i in range(skiprows):
|
|
28
|
+
f.readline()
|
|
29
|
+
return [j for j in f]
|
|
30
|
+
|
|
31
|
+
def setText(self, a: list):
|
|
32
|
+
with open(self.filename, 'w') as f:
|
|
33
|
+
if isinstance(a, list):
|
|
34
|
+
for i in a:
|
|
35
|
+
f.write(i+'\n')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os, time
|
|
2
|
+
|
|
3
|
+
def exists(filename: str, msg=True):
|
|
4
|
+
'''Confirm a file exists or not(Any files are okay).'''
|
|
5
|
+
a = os.path.isfile(filename)
|
|
6
|
+
if not msg:
|
|
7
|
+
return a
|
|
8
|
+
else:
|
|
9
|
+
if a:
|
|
10
|
+
print(f'UserWarning: File `{filename}` already exists!')
|
|
11
|
+
else:
|
|
12
|
+
print(f'UserWarning: File `{filename}` does not exist!')
|
|
13
|
+
|
|
14
|
+
def make(filename: str):
|
|
15
|
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
16
|
+
f.write(f'Author: {os.getcwd()}\nTime: ')
|
|
17
|
+
f.write(f'{time.strftime("%Y-%m-%d %H:%M:%S")}\n')
|
|
18
|
+
print(f'The file `{filename}` is created successfully.')
|
|
19
|
+
|
|
20
|
+
def makefile(filename: str, restart=False):
|
|
21
|
+
if exists(filename, msg=False):
|
|
22
|
+
exists(filename)
|
|
23
|
+
if restart:
|
|
24
|
+
print('Ignore warning. Restart file.')
|
|
25
|
+
make(filename)
|
|
26
|
+
else:
|
|
27
|
+
make(filename)
|
|
28
|
+
|
|
29
|
+
def rename(oldname: str, newname: str):
|
|
30
|
+
os.rename(oldname, newname)
|
|
31
|
+
print(f'The file `{oldname}` has changed to file `{newname}`.')
|
|
32
|
+
|
|
33
|
+
def delfile(filename: str):
|
|
34
|
+
os.remove(filename)
|
|
35
|
+
print(f'The file `{filename}` is deleted successfully.')
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
def bisection(f, a, b, e, showtimes=False):
|
|
2
|
+
'''
|
|
3
|
+
BISECTION
|
|
4
|
+
=========
|
|
5
|
+
A function to find roots of `f(x)=0` by bisection method.
|
|
6
|
+
`f(a)` and `f(b)` cannot have the same signs.
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
----------
|
|
10
|
+
f : func
|
|
11
|
+
`f` must be continuous. Python function returning a number.
|
|
12
|
+
a : float
|
|
13
|
+
Start of the bracketing interval [a,b].
|
|
14
|
+
b : float
|
|
15
|
+
End of the bracketing interval [a,b].
|
|
16
|
+
e : float
|
|
17
|
+
Accuracy
|
|
18
|
+
showtimes : bool. The default is False.
|
|
19
|
+
Show how many times the calculator use to find the root.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
iterations:
|
|
24
|
+
Returns if `showtimes` is True.
|
|
25
|
+
root : float
|
|
26
|
+
Root of `f` between `a` and `b`.
|
|
27
|
+
|
|
28
|
+
Examples
|
|
29
|
+
--------
|
|
30
|
+
Precise value::\n
|
|
31
|
+
>>> f = lambda x: x**2-1
|
|
32
|
+
>>> root = bisection(f, 0, 2, 0.01)
|
|
33
|
+
>>> root
|
|
34
|
+
1.0
|
|
35
|
+
|
|
36
|
+
Errors::\n
|
|
37
|
+
>>> root = bisection(f, -2, 2, 0.01)
|
|
38
|
+
ValueError: Incorrect input!
|
|
39
|
+
|
|
40
|
+
Approximate value::\n
|
|
41
|
+
>>> g = lambda x: -x**3-3*x+5
|
|
42
|
+
>>> root = bisection(g, 1, 2, 0.01)
|
|
43
|
+
>>> root
|
|
44
|
+
1.1484375
|
|
45
|
+
|
|
46
|
+
`showtimes` is True::\n
|
|
47
|
+
>>> bisection(g, 1, 2, 0.01, showtimes=True)
|
|
48
|
+
Finding root in 7 times.
|
|
49
|
+
1.1484375
|
|
50
|
+
'''
|
|
51
|
+
if f(a)*f(b)<0:
|
|
52
|
+
a1, b1 = a, b
|
|
53
|
+
i = 0
|
|
54
|
+
while not abs(a1-b1) < e:
|
|
55
|
+
i += 1
|
|
56
|
+
c = (a1+b1)/2
|
|
57
|
+
if f(c)==0:
|
|
58
|
+
return c
|
|
59
|
+
break
|
|
60
|
+
if f(c)*f(a1)<0:
|
|
61
|
+
b1 = c
|
|
62
|
+
if f(c)*f(b1)<0:
|
|
63
|
+
a1 = c
|
|
64
|
+
if showtimes:
|
|
65
|
+
print(f'Finding root in {i} times.')
|
|
66
|
+
return a1
|
|
67
|
+
else:
|
|
68
|
+
print('ValueError: Incorrect input!')
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from numpy import (linspace, sin, cos, tan, sinh, cosh, tanh, arcsin, arccos,
|
|
2
|
+
arctan, arcsinh, arccosh, arctanh, degrees, radians, sqrt,
|
|
3
|
+
log10, round, floor, ceil, sign, exp, log)
|
|
4
|
+
from scipy.special import gamma, erf
|
|
5
|
+
from .spf3d import (tri2d, ramp2d, rect2d, sign2d, step2d, sinc2d, gaus2d,
|
|
6
|
+
tri3d, ramp3d, rect3d, sign3d, step3d, sinc3d, gaus3d)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def diff1st(f0, x, h=0.01):
|
|
4
|
+
'''This is the 1st order derivative of a function.\n
|
|
5
|
+
.. math::
|
|
6
|
+
f'(x)=(f(x + h) - f(x - h))/(2*h)'''
|
|
7
|
+
return (f0(x + h) - f0(x - h))/(2*h)
|
|
8
|
+
|
|
9
|
+
def diff2nd(f0, x, h=0.01):
|
|
10
|
+
'''This is the 2nd order derivative of a function.\n
|
|
11
|
+
.. math::
|
|
12
|
+
f'(x)=(f(x-h)-2*f(x)+f(x+h))/(h*h)'''
|
|
13
|
+
return (f0(x-h)-2*f0(x)+f0(x+h))/(h*h)
|
|
14
|
+
|
|
15
|
+
class PC:
|
|
16
|
+
'''PC
|
|
17
|
+
==
|
|
18
|
+
This is a class of the calculation of pedal curves.\n
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
f(function), px1, py1(x, y of the point)\n
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
a, b: x, y of the function\n
|
|
25
|
+
x, y: x, y of pedal curves\n
|
|
26
|
+
Example
|
|
27
|
+
-------
|
|
28
|
+
>>> f = lambda x: x**2-1
|
|
29
|
+
>>> a = PC(f, 0, 0)
|
|
30
|
+
>>> a.a
|
|
31
|
+
array([-5. , -4.9989999, -4.9979998, ..., 4.9979998, 4.9989999,
|
|
32
|
+
5. ])'''
|
|
33
|
+
def __init__(self, f, px1, py1):
|
|
34
|
+
self.a = np.linspace(-5, 5, 10000)
|
|
35
|
+
self.b = f(self.a)
|
|
36
|
+
d = diff1st(f, self.a)
|
|
37
|
+
self.x = (self.a*d**2 + d*(py1 - self.b) + px1)/(d**2 + 1)
|
|
38
|
+
self.y = (py1*d**2 + self.b + px1 - self.a)/(d**2 + 1)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'''A module for 2d special functions.'''
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
def tri2d(x):
|
|
5
|
+
'''The 2d triangle function.'''
|
|
6
|
+
return np.where(abs(x) >= 1, 0, 1-abs(x))
|
|
7
|
+
|
|
8
|
+
def ramp2d(x):
|
|
9
|
+
'''The 2d ramp function.'''
|
|
10
|
+
return np.where(x > 0, abs(x), 0)
|
|
11
|
+
|
|
12
|
+
def rect2d(x):
|
|
13
|
+
'''The 2d rectangle function.'''
|
|
14
|
+
return np.where(abs(x) > 0.5, 0,
|
|
15
|
+
np.where(abs(x) == 0.5, 0.5, 1))
|
|
16
|
+
|
|
17
|
+
def sign2d(x):
|
|
18
|
+
'''The 2d sign function.'''
|
|
19
|
+
return np.where(x < 0, -1,
|
|
20
|
+
np.where(x == 0, 0, 1))
|
|
21
|
+
|
|
22
|
+
def step2d(x):
|
|
23
|
+
'''The 2d step function.'''
|
|
24
|
+
return np.where(x < 0, 0,
|
|
25
|
+
np.where(x == 0, 0.5, 1))
|
|
26
|
+
|
|
27
|
+
def gaus2d(x):
|
|
28
|
+
'''The 2d Gaussian Function.'''
|
|
29
|
+
return np.exp(-np.pi*x**2)
|
|
30
|
+
|
|
31
|
+
def sinc2d(x):
|
|
32
|
+
'''The 2d sinc function.'''
|
|
33
|
+
return np.where(x == 0, 1, np.sin(x)/x)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'''A module for 3d special functions.'''
|
|
2
|
+
from .spf2d import gaus2d, ramp2d, rect2d, sign2d, step2d, tri2d, sinc2d
|
|
3
|
+
|
|
4
|
+
def tri3d(x, y):
|
|
5
|
+
'''The 3d triangle function.'''
|
|
6
|
+
return tri2d(x)*tri2d(y)
|
|
7
|
+
|
|
8
|
+
def ramp3d(x, y):
|
|
9
|
+
'''The 3d ramp function.'''
|
|
10
|
+
return ramp2d(x)*ramp2d(y)
|
|
11
|
+
|
|
12
|
+
def rect3d(x, y):
|
|
13
|
+
'''The 3d rectangle function.'''
|
|
14
|
+
return rect2d(x)*rect2d(y)
|
|
15
|
+
|
|
16
|
+
def sign3d(x, y):
|
|
17
|
+
'''The 3d sign function.'''
|
|
18
|
+
return sign2d(x)*sign2d(y)
|
|
19
|
+
|
|
20
|
+
def step3d(x, y):
|
|
21
|
+
'''The 3d step function.'''
|
|
22
|
+
return step2d(x)*step2d(y)
|
|
23
|
+
|
|
24
|
+
def gaus3d(x, y):
|
|
25
|
+
'''The 3d Gaussian Function.'''
|
|
26
|
+
return gaus2d(x)*gaus2d(y)
|
|
27
|
+
|
|
28
|
+
def sinc3d(x, y):
|
|
29
|
+
'''The 3d sinc function.'''
|
|
30
|
+
return sinc2d(x)*sinc2d(y)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'''A module to generate docstrings for modules.'''
|
|
2
|
+
|
|
3
|
+
def generate_doc(module: str, abbr: str, func: str):
|
|
4
|
+
'''A function to generate docstring.'''
|
|
5
|
+
string = """
|
|
6
|
+
{0}
|
|
7
|
+
============================\n
|
|
8
|
+
How to use the documentation
|
|
9
|
+
----------------------------
|
|
10
|
+
We recommend exploring the docstrings using
|
|
11
|
+
`IPython <https://ipython.org>`_, an advanced Python shell with
|
|
12
|
+
TAB-completion and introspection capabilities. See below for further
|
|
13
|
+
instructions.\n
|
|
14
|
+
The docstring examples assume that `{0}` has been imported as `{1}`::\n
|
|
15
|
+
>>> import {0} as {1}
|
|
16
|
+
|
|
17
|
+
Use the built-in ``help`` function to view a function's docstring::\n
|
|
18
|
+
>>> help({1}.{2})
|
|
19
|
+
... # doctest: +SKIP
|
|
20
|
+
|
|
21
|
+
Utilities
|
|
22
|
+
---------
|
|
23
|
+
__version__
|
|
24
|
+
{0} version string
|
|
25
|
+
|
|
26
|
+
Viewing documentation using IPython
|
|
27
|
+
-----------------------------------
|
|
28
|
+
To see which functions are available in `{0}`, type ``{1}.<TAB>``
|
|
29
|
+
(where ``<TAB>`` refers to the TAB key), or use ``{1}.*{2}*?<ENTER>``
|
|
30
|
+
(where ``<ENTER>`` refers to the ENTER key) to narrow down the list.
|
|
31
|
+
To view the docstring for a function, use ``{1}.{2}?<ENTER>`` (to view
|
|
32
|
+
the docstring) and ``{1}.{2}??<ENTER>`` (to view the source
|
|
33
|
+
code).""".format(module, abbr, func)
|
|
34
|
+
return string
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import kitpylib as kpl
|
|
3
|
+
|
|
4
|
+
def confirm_info(all_modules):
|
|
5
|
+
'''Confirm name, version of a module.'''
|
|
6
|
+
name = all_modules.__name__
|
|
7
|
+
version = all_modules.__version__
|
|
8
|
+
return name, version
|
|
9
|
+
|
|
10
|
+
def mod_setup(module, **attrs):
|
|
11
|
+
'''modules' setup. Need version string(__version__).\n
|
|
12
|
+
**attrs: except `name`, `version` and `py_modules`.'''
|
|
13
|
+
_name, _version = confirm_info(module)
|
|
14
|
+
setup(name=_name, version=_version, py_modules=[_name], **attrs)
|
|
15
|
+
|
|
16
|
+
def pkg_setup(package, **attrs):
|
|
17
|
+
'''packages' setup. Need version string(__version__).\n
|
|
18
|
+
**attrs: except `name`, `version` and `packages`.'''
|
|
19
|
+
_name, _version= confirm_info(package)
|
|
20
|
+
setup(name=_name, packages=find_packages(), version=_version, **attrs)
|
|
21
|
+
|
|
22
|
+
def my_setup(pkg, **attrs):
|
|
23
|
+
'''S_My setup tools.'''
|
|
24
|
+
pkg_setup(pkg,
|
|
25
|
+
classifiers = ['Operating System :: Microsoft :: Windows :: Windows 11',
|
|
26
|
+
'Operating System :: Microsoft :: Windows :: Windows 7',
|
|
27
|
+
'Programming Language :: Python :: 3',
|
|
28
|
+
'Programming Language :: Python :: 3.9',
|
|
29
|
+
'License :: OSI Approved :: MIT License'],
|
|
30
|
+
long_description = pkg.__doc__,
|
|
31
|
+
long_description_content_type='text/x-rst',
|
|
32
|
+
license=f'MIT License({kpl.__copr__})',
|
|
33
|
+
author=kpl.myinfo['author'],
|
|
34
|
+
author_email=kpl.myinfo['email'],
|
|
35
|
+
**attrs)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
myinfo={'author': 'S_My',
|
|
2
|
+
'email': 'mingyang3sun@hotmail.com',
|
|
3
|
+
'copyright':'Copyright (c) 2025-2026, S_My Programming Team & '\
|
|
4
|
+
'KitPy Developers'}
|
|
5
|
+
|
|
6
|
+
mit_license='''
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person
|
|
9
|
+
obtaining a copy of this software and associated documentation
|
|
10
|
+
files (the “Software”), to deal in the Software without
|
|
11
|
+
restriction, including without limitation the rights to use,
|
|
12
|
+
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
13
|
+
sell copies of the Software, and to permit persons to whom the
|
|
14
|
+
Software is furnished to do so, subject to the following
|
|
15
|
+
conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be
|
|
18
|
+
included in all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
22
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
24
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
25
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
26
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
27
|
+
OTHER DEALINGS IN THE SOFTWARE.'''
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'Matplotlib.PyPlot backend for plotting.'
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import matplotlib as mpl
|
|
4
|
+
|
|
5
|
+
def plot2d(x, y, px=None, py=None, grid=False, title=None, legend=None,
|
|
6
|
+
axh=False, axv=False, *args):
|
|
7
|
+
'''
|
|
8
|
+
plot2d
|
|
9
|
+
======
|
|
10
|
+
|
|
11
|
+
Example
|
|
12
|
+
-------
|
|
13
|
+
|
|
14
|
+
With all arguments:
|
|
15
|
+
|
|
16
|
+
>>> import kitpy as kp
|
|
17
|
+
>>> a=[0, 1, 2, 3, 4, 5, 6, 7, 8]
|
|
18
|
+
>>> b=[0, 1, 2, 1, 2, 3, 2, 3, 4]
|
|
19
|
+
>>> kp.plot2d(a, b, px=a, py=b, grid=True, title='a simple plot',
|
|
20
|
+
legend='plot', axh=True, axv=True)
|
|
21
|
+
|
|
22
|
+
.. image:: image0.png
|
|
23
|
+
|
|
24
|
+
With only optional arguments:
|
|
25
|
+
|
|
26
|
+
>>> kp.plot2d(a, b)
|
|
27
|
+
|
|
28
|
+
.. image:: image1.png'''
|
|
29
|
+
if not mpl.get_backend == 'qt5agg':
|
|
30
|
+
plt.switch_backend('qt5agg')
|
|
31
|
+
fig, ax = plt.subplots()
|
|
32
|
+
ax.plot(x, y, label=legend)
|
|
33
|
+
ax.plot(*args)
|
|
34
|
+
if px is not None and py is not None:
|
|
35
|
+
ax.plot(px, py, 'og', ms=7.5, mfc='white', label='point')
|
|
36
|
+
if axh:
|
|
37
|
+
ax.axhline(color='black', linestyle='--', zorder=-1)
|
|
38
|
+
if axv:
|
|
39
|
+
ax.axvline(color='black', linestyle='--', zorder=-1)
|
|
40
|
+
ax.set_xlabel('x')
|
|
41
|
+
ax.set_ylabel('y')
|
|
42
|
+
ax.grid(grid)
|
|
43
|
+
if not title == None:
|
|
44
|
+
ax.set_title(title)
|
|
45
|
+
if not legend == None:
|
|
46
|
+
ax.legend(numpoints=1, fontsize='small',
|
|
47
|
+
loc='upper right',
|
|
48
|
+
bbox_to_anchor=(0.9, 0.97))
|
|
49
|
+
fig.show()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .backend import plot2d
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
|
|
5
|
+
def fplot2d(f, start, stop, num=100, *args, **kwargs):
|
|
6
|
+
'''
|
|
7
|
+
A function to plot 2d functions.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
f : f(x)
|
|
12
|
+
The function to plot.
|
|
13
|
+
start : number
|
|
14
|
+
The starting value of the sequence.
|
|
15
|
+
stop : number
|
|
16
|
+
The end value of the sequence.
|
|
17
|
+
num : number, optional
|
|
18
|
+
Number of samples to generate. The default is 100.
|
|
19
|
+
*args : optional
|
|
20
|
+
See documentation of `kp.plot2d`.'''
|
|
21
|
+
a = np.linspace(start, stop, num)
|
|
22
|
+
plot2d(a, f(a), *args, **kwargs)
|
|
23
|
+
|
|
24
|
+
def fplot3d(f, xstart, xstop, ystart, ystop, num=100):
|
|
25
|
+
'''
|
|
26
|
+
A function to plot 3d functions.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
f : f(x)
|
|
31
|
+
The function to plot.
|
|
32
|
+
num : number, optional
|
|
33
|
+
Number of samples to generate. The default is 100.
|
|
34
|
+
For X:
|
|
35
|
+
======
|
|
36
|
+
xstart : int
|
|
37
|
+
The starting value of the sequence x.
|
|
38
|
+
xstop : int
|
|
39
|
+
The end value of the sequence x.
|
|
40
|
+
For Y:
|
|
41
|
+
======
|
|
42
|
+
ystart : int
|
|
43
|
+
The starting value of the sequence y.
|
|
44
|
+
ystop : int
|
|
45
|
+
The end value of the sequence y.'''
|
|
46
|
+
A = np.linspace(xstart, xstop, num)
|
|
47
|
+
B = np.linspace(ystart, ystop, num)
|
|
48
|
+
a, b = np.meshgrid(A, B)
|
|
49
|
+
c = f(a, b)
|
|
50
|
+
fig, ax = plt.subplots(1, 2, figsize=(9.2, 4),
|
|
51
|
+
subplot_kw={'projection':'3d'})
|
|
52
|
+
for i in range(2):
|
|
53
|
+
ax[i].set_zlim(-3,2)
|
|
54
|
+
ax[i].set_xlabel(r'$x$')
|
|
55
|
+
ax[i].set_ylabel(r'$y$')
|
|
56
|
+
ax[i].set_zlabel(r'$f(x,y)$')
|
|
57
|
+
ax[i].view_init(40, -30)
|
|
58
|
+
plt.subplots_adjust(left=0.04, bottom=0.04, right=0.96,
|
|
59
|
+
top=0.96, wspace=0.05)
|
|
60
|
+
p0 = ax[0].plot_wireframe(a,b,c,rcount=40,ccount=40,color='C1')
|
|
61
|
+
p1 = ax[1].plot_surface(a,b,c,rcount=50,ccount=50,color='C1')
|
|
62
|
+
plt.subplots_adjust(left=0.0)
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'''
|
|
2
|
+
KitPyLib
|
|
3
|
+
========
|
|
4
|
+
|
|
5
|
+
A Python Library of basic tools.
|
|
6
|
+
|
|
7
|
+
How to use
|
|
8
|
+
----------
|
|
9
|
+
We recommend you to import `kitpy` as ``kp``:\n
|
|
10
|
+
>>> import kitpy as kp
|
|
11
|
+
>>> kp.fplot2d(lambda x: x**3, 0, 2)
|
|
12
|
+
|
|
13
|
+
Use the built-in ``help`` function to view a function's docstring:\n
|
|
14
|
+
>>> help(kp.fplot2d)
|
|
15
|
+
... # doctest: +SKIP
|
|
16
|
+
|
|
17
|
+
Available subpackages
|
|
18
|
+
---------------------
|
|
19
|
+
PyFile
|
|
20
|
+
KitPy's subpackage to solve txt file problems
|
|
21
|
+
PyWidget
|
|
22
|
+
KitPy's subpackage about qt widgets
|
|
23
|
+
|
|
24
|
+
Utilities
|
|
25
|
+
---------
|
|
26
|
+
__version__
|
|
27
|
+
KitPy version string
|
|
28
|
+
__copr__
|
|
29
|
+
KitPy copyright string
|
|
30
|
+
__lic__
|
|
31
|
+
KitPy license string
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
from .init import *
|
|
35
|
+
__version__ = '1.0.0'
|
|
36
|
+
__copr__ = myinfo['copyright']
|
|
37
|
+
__lic__ = __copr__ + mit_license
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kitpylib
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python Library of Basic Tools
|
|
5
|
+
Author: S_My
|
|
6
|
+
Author-email: mingyang3sun@hotmail.com
|
|
7
|
+
License: MIT License(Copyright (c) 2025-2026, S_My Programming Team & KitPy Developers)
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 7
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/x-rst
|
|
15
|
+
Requires-Dist: numpy>=1.26.4
|
|
16
|
+
Requires-Dist: matplotlib>=3.9.2
|
|
17
|
+
Requires-Dist: scipy>=1.13.1
|
|
18
|
+
Requires-Dist: setuptools>=72.1.0
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: license
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
KitPyLib
|
|
31
|
+
========
|
|
32
|
+
|
|
33
|
+
A Python Library of basic tools.
|
|
34
|
+
|
|
35
|
+
How to use
|
|
36
|
+
----------
|
|
37
|
+
We recommend you to import `kitpy` as ``kp``:
|
|
38
|
+
|
|
39
|
+
>>> import kitpy as kp
|
|
40
|
+
>>> kp.fplot2d(lambda x: x**3, 0, 2)
|
|
41
|
+
|
|
42
|
+
Use the built-in ``help`` function to view a function's docstring:
|
|
43
|
+
|
|
44
|
+
>>> help(kp.fplot2d)
|
|
45
|
+
... # doctest: +SKIP
|
|
46
|
+
|
|
47
|
+
Available subpackages
|
|
48
|
+
---------------------
|
|
49
|
+
PyFile
|
|
50
|
+
KitPy's subpackage to solve txt file problems
|
|
51
|
+
PyWidget
|
|
52
|
+
KitPy's subpackage about qt widgets
|
|
53
|
+
|
|
54
|
+
Utilities
|
|
55
|
+
---------
|
|
56
|
+
__version__
|
|
57
|
+
KitPy version string
|
|
58
|
+
__copr__
|
|
59
|
+
KitPy copyright string
|
|
60
|
+
__lic__
|
|
61
|
+
KitPy license string
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
kitpylib/__init__.py
|
|
3
|
+
kitpylib/init.py
|
|
4
|
+
kitpylib.egg-info/PKG-INFO
|
|
5
|
+
kitpylib.egg-info/SOURCES.txt
|
|
6
|
+
kitpylib.egg-info/dependency_links.txt
|
|
7
|
+
kitpylib.egg-info/requires.txt
|
|
8
|
+
kitpylib.egg-info/top_level.txt
|
|
9
|
+
kitpylib/PyFile/__init__.py
|
|
10
|
+
kitpylib/PyFile/classes.py
|
|
11
|
+
kitpylib/PyFile/funcs.py
|
|
12
|
+
kitpylib/PyMath/__init__.py
|
|
13
|
+
kitpylib/PyMath/findroot.py
|
|
14
|
+
kitpylib/PyMath/mathfuncs.py
|
|
15
|
+
kitpylib/PyMath/spf1d.py
|
|
16
|
+
kitpylib/PyMath/spf2d.py
|
|
17
|
+
kitpylib/PyMath/spf3d.py
|
|
18
|
+
kitpylib/PyModule/__init__.py
|
|
19
|
+
kitpylib/PyModule/docstr.py
|
|
20
|
+
kitpylib/PyModule/install.py
|
|
21
|
+
kitpylib/PyModule/license.py
|
|
22
|
+
kitpylib/PyPlot/__init__.py
|
|
23
|
+
kitpylib/PyPlot/backend.py
|
|
24
|
+
kitpylib/PyPlot/funcplot.py
|
|
25
|
+
kitpylib/PyPlot/image0.png
|
|
26
|
+
kitpylib/PyPlot/image1.png
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kitpylib
|
kitpylib-1.0.0/setup.cfg
ADDED
kitpylib-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import kitpylib as kpl
|
|
2
|
+
|
|
3
|
+
kpl.my_setup(kpl,
|
|
4
|
+
install_requires=["numpy>=1.26.4",
|
|
5
|
+
"matplotlib>=3.9.2",
|
|
6
|
+
"scipy>=1.13.1",
|
|
7
|
+
"setuptools>=72.1.0"
|
|
8
|
+
],
|
|
9
|
+
package_data={'kitpylib': ['PyPlot/*.png']},
|
|
10
|
+
include_package_data=True,
|
|
11
|
+
description='A Python Library of Basic Tools',
|
|
12
|
+
python_requires='>=3.9'
|
|
13
|
+
)
|