Matplotlib wave plotting and animation made easy
Project description
Moonlight
Matplotlib wave plotting and animation made easy
Installation
- For pip release -
pip install moonlight
- For source build -
git clone https://github.com/CharlesAverill/moonlight.git moonlight
cd moonlight
python setup.py install
Usage
from moonlight import waves, utils
# Create a damped Sine wave with amplitude, period 2
sine = waves.Sine(amplitude=2, period=2,
decay_constant=.25)
# Set range of plot
utils.x_range(-3, 3)
utils.y_range(-4, 4)
# Move axes to center
utils.center_axes()
# Plot 2 periods of the wave (static)
sine.plot(2)
Animation
Waves can also be animated! Just replace <wave_object>.plot()
with <wave_object>.animate()
!
animate
parameters
speed
- The speed at which the animation will play. Some waves have their default speed adjusted so that animation can be seen easily.- When combining a
Square
orSawtooth
wave with aSine
orCosine
wave, the sum of the functions naturally grows at an incredibly slow rate, sospeed
should be set to a multiple of10**14
to be able to view animations properly.
- When combining a
line_width
- Sets line widthframerate
- Measured in ms, this is the time gap between two frames being displayed. Default is 17ms or ~60fps.
Supported Waves
Sine
Cosine
Square
Sawtooth
Wave
- This is a parent class for the previous waves. Custom waves can be implemented by inheriting this class.
Wave parameters
amplitude: float = 1
- Initial wave amplitudeperiod: float = <varies by wave>
- Period of waveoffsets: Tuple(float [x], float [y]) = (0, 0)
- X- and Y- offsets of the wavedecay_constant: float = 0
- If nonzero, function will decay according toe^(-<decay>x)wavefunc(x)
. Trig functions only.resolution: int = 500
- Number of x-values that will be generated upon graphing.
Wave operators
Waves can be operated on by each other and by scalar values.
from moonlight.waves import Sine
s1 = Sine()
s2 = Sine(amplitude=2)
add_waves = s1 + s2 # sin(x) + 2sin(x) = 3sin(x)
add_scalar = s1 + 3 # sin(x) + 3
sub_waves = s1 - s2 # sin(x) - 2sin(x) = -sin(x)
sub_scalar = s1 - 3 # sin(x) - 3
mul_waves = s1 * s2 # sin(x) * 2sin(x) = 2sin(x)^2
mul_scalar = s1 * 3 # sin(x) * 3 = 3sin(x)
div_waves = s1 / s2 # sin(x) / 2sin(x) = 1/2
div_scalar = s1 / 3 # sin(x) / 3 = (1/3)sin(x)
call_waves = s1(s2) # sin(2sin(x))
call_scalar = s1(3) # sin(3) ≈ .14112
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for moonlightplt-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 984ac041442f64ea6f55729bd7aae72508d27d2e62ccb583d2326f0b8c45f4bb |
|
MD5 | c6435752b02954b8edb27f9a11a6c9fa |
|
BLAKE2b-256 | f51fc5fe2f64aa99a76588d4ae56d3e590feaee2ed2a69ce65274c0f9827096f |