flashplot documentation
Usage
Here’s a short example script going over basic usage:
1import numpy as np
2import flashplot as fp
3
4def main():
5
6 #
7 # fp.imshow
8 #
9
10 # generate a random image, should just be static
11 A = np.random.rand(200,200)
12 img = fp.imshow(A)
13
14 #
15 # fp.plot
16 #
17
18 # generate a sine wave plot
19 xs = np.linspace(0,10,100)
20 ys = np.sin(xs)
21
22 img = fp.plot(xs, ys)
23
24 #
25 # fp.make_mp4_from_data
26 #
27
28 # generate a bunch of static data and make an mp4
29 frames = []
30 n_frames = 100
31 for i in range(n_frames):
32 A = np.random.rand(200,200)
33 frames.append(A)
34
35 fp.make_mp4_from_data(frames, 'frames.mp4')
36
37 #
38 # fp.show_mp4
39 #
40
41 # now show the movie we just made
42 fp.show_mp4('frames.mp4')
43
44if __name__=='__main__':
45 main()
API Reference
- flashplot.imshow(arr, scale: float | None = None, int_scale: int | None = None, title: str | None = None, size: tuple | None = None, cmap=None, **kwargs)
Meant to replicate plt.imshow().
- Parameters:
arr (numpy.ndarray) – Image array that gets rescaled from 0 to 255
scale (float or None) – The float scaling, uses lanczos resampling to scale this will interpolate some pixels and smooth out features slightly
int_scale (int or None) – The integer scaling using nearest neighbor resampling to scale use this to preserve fine pixel details
title (str or None) – Add title to bottom of image
size (tuple or None) – The size of the output image
cmap (str or None) – The colormap to use
kwargs –
Additional keyword arguments including:
vmin (
float): lower clipvmax (
float): upper cliplog_scale (
bool): log scale the imagefont (
str): font for title
- Returns:
The processed image
- Return type:
PIL.Image.Image
- flashplot.plot(plot_xs, plot_ys, x_min=None, x_max=None, y_min=None, y_max=None, size=(300, 300), padding=10)
Plots the given x and y data with optional axis limits and padding.
- Parameters:
plot_xs (array-like) – The x data to plot
plot_ys (array-like) – The y data to plot
x_min (float or None) – The minimum x value
x_max (float or None) – The maximum x value
y_min (float or None) – The minimum y value
y_max (float or None) – The maximum y value
size (tuple) – The size of the plot in pixels
padding (int) – The padding around the plot
- Returns:
The plotted image
- Return type:
PIL.Image.Image
- flashplot.make_mp4_from_data(data, save_path, keep_frames=False, frames_folder='fp_frames_temp', frame_name='frame', framerate=24, use_tqdm=True, titles=None, **kwargs)
Makes an MP4 using ffmpeg, pass the arrays of data directly and this function will call imshow to generate each frame.
- Parameters:
data (array-like) – The image data to include in the video
save_path (str or pathlib.Path) – The path to save the resulting MP4 file
keep_frames (bool) – Whether to keep the individual frame images
frames_folder (str) – The folder to store the individual frame images
frame_name (str) – The base name for the frame image files
framerate (int) – The framerate for the resulting video
use_tqdm (bool) – Whether to use tqdm for progress tracking
titles (list or None) – Optional titles for each frame
kwargs – Additional keyword arguments passed to imshow
- flashplot.make_mp4_from_files(pattern, save_path, framerate)
Make an mp4 file from files that are already written. Needs a pattern to work.
- Parameters:
pattern (str or pathlib.Path) – The filename save pattern ie: ‘frame_%04d.png’ corresponds to frame_0000.png, frame_0001.png, frame_0002.png, etc.
save_path (str or pathlib.Path) – The complete path we will be saving to should end in .mp4 e.g. ‘saveme/name.mp4’
framerate (int) – The framerate of the ending movie
- flashplot.show_mp4(filename)
Shows the mp4 file after its made using the lightweight ffplay player ffplay comes with ffmpeg!
- Parameters:
filename (str or pathlib.Path) – The path to the mp4 file to show