Skip to main content

A thin wrapper for matplotlib

Fplot’s goal is to provide simple syntax for plotting functions, with sensible defaults. Matplotlib is powerful, but has awkward syntax, odd default display settings, and requires setting up data arrays manually. Making pretty function plots requires multiple lines of code. Fplot aims to fix this; it’s especially suited for visualizing functions when learning math.

Python 3 only.

Included functions

  • plot: One input, one output.

  • parametric: One input, two or three outputs. If three, use a 3d graph.

  • contour: Two inputs, one output.

  • surface: Two inputs, one output.

  • vector: Two inputs, two outputs.

  • vector3d: Three inputs, three outputs.

  • polar: One input (angle), one output (radius)

Bonus functions

  • plot2: Smoothed API for matplotlib 2d plotting that works properly in Jupyter notebooks. ie syntax like plt.plot, which doesn’t work properly in Jupyter. Arguments: (args, marker=’b-’, linewidth: float=2.0, grid: bool=False, color: str=None, title: str=None, equal_aspect: bool=False, style: str=None, show: bool=True)

  • imshow: Like plot2, but as a replacement for plt.imshow.

Installation

pip install fplot

Basic documentation

Examples

The only required arguments for fplot funcs are the function to plot, and the min and max ranges. Example optional keyword arguments are shown. Example output is shown in the link above.

For most plotting functions, you can plot multiple functions at once by passing a list or tuple as the first argument.

Show a graph (1 input, 1 output)

f = lambda x: x**2 + 2
fplot.plot(f, -10, 10, title='Hello world')

Show a contour plot (2 inputs, 1 output)

g = lambda x, y: x**2 + y**2 + 10
fplot.contour(g, -10, 10, equal_aspect=True)

Show a surface plot (2 inputs, 1 output)

g = lambda x, y: x**2 + y**2 + 10
fplot.surface(g, -10, 10)

Show a 2d parametric plot (1 input, 2 outputs)

h = lambda t: (np.sin(t), np.cos(t))
fplot.parametric(h, 0, Ï„, equal_aspect=True, color='m')

Show a 3d parametric plot (1 input, 3 outputs)

i = lambda t: (np.sin(t), np.cos(t), t**2)
fplot.parametric(i, 0, 20, color='red')

Show a 2d vector plot (2 inputs, 2 outputs)

f = lambda x, y: (x**2 + y, y**2 * cos(x))
fplot.vector(f, -10, 10, stream=False)

Show a 3d vector plot (3 inputs, 3 outputs)

f = lambda x, y, z: (x**2, y**2, z)
fplot.vector3d(f, -10, 10)

Show a 2d polar plot (1 input, 1 output)

f = lambda theta: np.sin(3*theta)
fplot.polar(f, 0, tau, color='purple')

Example of an interactive plot with Ipython widgets in Jupyter notebook

from numpy import sin, cos
from ipywidgets import interactive
import fplot

def make_plot(a, b):
    f = lambda t: (a*sin(t), a*cos(t), b*t)
    ax = fplot.parametric(f, -20, 20, show=False)

    ax.set_xlim3d(-3, 3)
    ax.set_ylim3d(-3, 3)
    ax.set_zlim3d(-3, 3)
    plt.show()

interactive_plot = interactive(make_plot, a=(-2.0, 2.0), b=(-3.0, 3.0))
interactive_plot
Optional arguments:
  • show: Defaults to True. Instantly display the plot. If False, return the axis object.

  • resolution: Controls how many points to draw, based on function input. Higher resolution allows more zooming, but may lower performance.

  • color: (ie line color)

  • linewidth: line width.

  • y_min and y_max: (only for 2d input)

  • theta_min and theta_max (only for polar plots)

  • style: (ie from plt.use.style())

  • grid: defaults to True

  • equal_aspect: defaults to False

  • title: Shown at the top of the plot

  • stream: vector plot only; show a stream plot if True

  • contours: surface plot only; show contour plots along each axis if True

  • num_contours: contour plot only; set number of contour lines to draw. Defaults to 10.

Metadata

Release files for fplot 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fplot 0.2.4
File Interpreter ABI Platform
fplot-0.2.4-py3-none-any.whl Python 3 none any Details

Release files / fplot-0.2.4-py3-none-any.whl

Download URL fplot-0.2.4-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66ccd83697232a21b38206eb49d33003973ffbd88caba496b90377830da890db
BLAKE2b-256 checksum
How to use checksums
06b4b51d9063e3ba8aa91e40315ad3d7e925520a9b648b79702e43d0afaaf80d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.2.4 This release

1 release file

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page