CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-matplotlib

Comprehensive Python library for creating static, animated, and interactive visualizations

Pending
Overview
Eval results
Files

pyplot.mddocs/

Pyplot Interface

State-based MATLAB-like interface that maintains a current figure and axes, making it easy to build up plots incrementally. This interface is ideal for interactive work and simple scripts.

Core Concepts

The pyplot interface maintains global state:

  • Current figure (gcf())
  • Current axes (gca())
  • Automatic figure/axes creation when needed

Capabilities

Figure Management

Create, manage, and display figures.

def figure(num=None, figsize=None, dpi=None, facecolor=None, 
          edgecolor=None, frameon=True, FigureClass=Figure, 
          clear=False, **kwargs) -> Figure:
    """Create a new figure or activate an existing figure."""

def gcf() -> Figure:
    """Get the current figure."""

def fignum_exists(num) -> bool:
    """Return whether the figure with the given id exists."""

def show(*args, **kwargs) -> None:
    """Display all open figures."""

def savefig(fname, *, dpi='figure', format=None, metadata=None,
           bbox_inches=None, pad_inches=0.1, facecolor='auto',
           edgecolor='auto', backend=None, **kwargs) -> None:
    """Save the current figure."""

def close(fig=None) -> None:
    """Close a figure window."""

def clf() -> None:
    """Clear the current figure."""

def cla() -> None:  
    """Clear the current axes."""

Basic Plotting

Fundamental plot types for data visualization.

def plot(*args, scalex=True, scaley=True, data=None, **kwargs) -> list:
    """Plot y versus x as lines and/or markers."""

def scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None,
           vmin=None, vmax=None, alpha=None, linewidths=None,
           edgecolors=None, plotnonfinite=False, **kwargs) -> PathCollection:
    """Make a scatter plot of x vs y."""

def bar(x, height, width=0.8, bottom=None, *, align='center',
       data=None, **kwargs) -> BarContainer:
    """Make a bar plot."""

def barh(y, width, height=0.8, left=None, *, align='center',
        data=None, **kwargs) -> BarContainer:
    """Make a horizontal bar plot."""

def hist(x, bins=None, range=None, density=False, weights=None,
        cumulative=False, bottom=None, histtype='bar', align='mid',
        orientation='vertical', rwidth=None, log=False, color=None,
        label=None, stacked=False, **kwargs) -> tuple:
    """Compute and plot a histogram."""

def pie(x, explode=None, labels=None, colors=None, autopct=None,
       pctdistance=0.6, shadow=False, labeldistance=1.1,
       startangle=0, radius=1, counterclock=True, wedgeprops=None,
       textprops=None, center=(0, 0), frame=False, rotatelabels=False,
       normalize=True, **kwargs) -> tuple:
    """Plot a pie chart."""

Statistical Plots

Specialized plots for statistical data visualization.

def boxplot(x, notch=None, sym=None, vert=None, whis=None,
           positions=None, widths=None, patch_artist=None,
           bootstrap=None, usermedians=None, conf_intervals=None,
           meanline=None, showmeans=None, showcaps=None,
           showbox=None, showfliers=None, boxprops=None,
           labels=None, flierprops=None, medianprops=None,
           meanprops=None, capprops=None, whiskerprops=None,
           manage_ticks=True, autorange=False, zorder=None,
           capwidths=None, **kwargs) -> dict:
    """Make a box and whisker plot."""

def violinplot(dataset, positions=None, vert=True, widths=0.5,
              showmeans=False, showextrema=True, showmedians=False,
              quantiles=None, points=100, bw_method=None, **kwargs) -> dict:
    """Make a violin plot."""

def errorbar(x, y, yerr=None, xerr=None, fmt='', ecolor=None,
            elinewidth=None, capsize=None, barsabove=False,
            lolims=False, uplims=False, xlolims=False, xuplims=False,
            errorevery=1, capthick=None, **kwargs) -> ErrorbarContainer:
    """Plot y versus x with error bars."""

2D Visualization

Functions for displaying 2D data and images.

def imshow(X, cmap=None, norm=None, aspect=None, interpolation=None,
          alpha=None, vmin=None, vmax=None, origin=None, extent=None,
          filternorm=True, filterrad=4.0, resample=None, url=None,
          **kwargs) -> AxesImage:
    """Display data as an image."""

def contour(X, Y, Z, levels=None, **kwargs) -> QuadContourSet:
    """Draw contour lines."""

def contourf(X, Y, Z, levels=None, **kwargs) -> QuadContourSet:
    """Draw filled contours."""

def pcolormesh(X, Y, C, **kwargs) -> QuadMesh:
    """Create a pseudocolor plot with a non-regular rectangular grid."""

def quiver(X, Y, U, V, C=None, **kwargs) -> Quiver:
    """Plot a 2D field of arrows."""

def streamplot(x, y, u, v, density=1, linewidth=None, color=None,
              cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
              minlength=0.1, transform=None, zorder=None,
              start_points=None, maxlength=4.0, integration_direction='both',
              **kwargs) -> StreamplotSet:
    """Draw streamlines of a vector flow."""

Specialized Plots

Additional plot types for specific use cases.

def step(x, y, *args, where='pre', data=None, **kwargs) -> list:
    """Make a step plot."""

def stem(x, y, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
        label=None, use_line_collection=True, orientation='vertical',
        **kwargs) -> StemContainer:
    """Create a stem plot."""

def fill_between(x, y1, y2=0, where=None, interpolate=False, step=None,
                **kwargs) -> PolyCollection:
    """Fill the area between two horizontal curves."""

def fill_betweenx(y, x1, x2=0, where=None, step=None, interpolate=False,
                 **kwargs) -> PolyCollection:
    """Fill the area between two vertical curves."""

def polar(*args, **kwargs) -> list:
    """Make a polar plot."""

def loglog(*args, **kwargs) -> list:
    """Make a plot with log scaling on both the x and y axis."""

def semilogx(*args, **kwargs) -> list:
    """Make a plot with log scaling on the x axis."""

def semilogy(*args, **kwargs) -> list:
    """Make a plot with log scaling on the y axis."""

Axes and Subplot Management

Control plot layout and subplot organization.

def subplot(nrows, ncols, index, **kwargs) -> Axes:
    """Add an axes to the current figure or retrieve an existing axes."""

def subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True,
            width_ratios=None, height_ratios=None, subplot_kw=None,
            gridspec_kw=None, **fig_kw) -> tuple:
    """Create a figure and a set of subplots."""

def subplot_mosaic(mosaic, *, sharex=False, sharey=False, width_ratios=None,
                  height_ratios=None, empty_sentinel='.', subplot_kw=None,
                  gridspec_kw=None, **fig_kw) -> tuple:
    """Build a layout of Axes based on ASCII art or nested lists."""

def gca(**kwargs) -> Axes:
    """Get the current Axes."""

def sca(ax) -> None:
    """Set the current Axes."""

def delaxes(ax=None) -> None:
    """Remove an axes from its figure."""

Labeling and Annotation

Add text, labels, and annotations to plots.

def xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs) -> Text:
    """Set the label for the x-axis."""

def ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs) -> Text:
    """Set the label for the y-axis."""

def title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs) -> Text:
    """Set a title for the Axes."""

def suptitle(t, **kwargs) -> Text:
    """Add a centered suptitle to the figure."""

def text(x, y, s, fontdict=None, **kwargs) -> Text:
    """Add text to the Axes."""

def annotate(text, xy, xytext=None, xycoords='data', textcoords=None,
            arrowprops=None, annotation_clip=None, **kwargs) -> Annotation:
    """Annotate the point xy with text."""

def legend(*args, **kwargs) -> Legend:
    """Place a legend on the Axes."""

def figtext(x, y, s, fontdict=None, **kwargs) -> Text:
    """Add text to figure."""

Axis Control

Manage axis limits, scaling, and appearance.

def xlim(left=None, right=None) -> tuple:
    """Get or set the x limits of the current axes."""

def ylim(bottom=None, top=None) -> tuple:
    """Get or set the y limits of the current axes."""

def axis(arg=None, /, *, emit=True, **kwargs):
    """Convenience method to get or set some axis properties."""

def grid(visible=None, which='major', axis='both', **kwargs) -> None:
    """Configure the grid lines."""

def xticks(ticks=None, labels=None, *, minor=False, **kwargs) -> tuple:
    """Get or set the current tick locations and labels of the x-axis."""

def yticks(ticks=None, labels=None, *, minor=False, **kwargs) -> tuple:
    """Get or set the current tick locations and labels of the y-axis."""

def tick_params(axis='both', **kwargs) -> None:
    """Change the appearance of ticks, tick labels, and gridlines."""

def minorticks_on() -> None:
    """Display minor ticks on the axes."""

def minorticks_off() -> None:
    """Remove minor ticks from the axes."""

Layout and Formatting

Control plot layout and visual formatting.

def tight_layout(*, pad=1.08, h_pad=None, w_pad=None, rect=None) -> None:
    """Adjust the padding between and around subplots."""

def colorbar(mappable=None, cax=None, ax=None, **kwargs) -> Colorbar:
    """Add a colorbar to a plot."""

def clim(vmin=None, vmax=None) -> tuple:
    """Set the color limits of the current image."""

def margins(*margins, x=None, y=None, tight=True) -> tuple:
    """Set or retrieve autoscaling margins."""

def setp(obj, *args, **kwargs):
    """Set one or more properties on an Artist, or list allowed values."""

def getp(obj, property=None):
    """Return the value of an Artist's property, or print all of them."""

Usage Examples

Simple Line Plot

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)

plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')
plt.xlabel('X values')
plt.ylabel('Y values')
plt.title('Sine Wave')
plt.legend()
plt.grid(True)
plt.show()

Multiple Subplots

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 10))

# Plot different things in each subplot
ax1.plot(x, np.sin(x))
ax1.set_title('Sine')

ax2.plot(x, np.cos(x))  
ax2.set_title('Cosine')

ax3.scatter(x[::10], np.sin(x[::10]))
ax3.set_title('Sine Scatter')

ax4.bar(range(5), [1, 3, 2, 5, 4])
ax4.set_title('Bar Chart')

plt.tight_layout()
plt.show()

Statistical Plot

# Generate sample data
data = np.random.normal(100, 15, size=(3, 100))

plt.figure(figsize=(10, 6))
plt.boxplot(data, labels=['Group A', 'Group B', 'Group C'])
plt.ylabel('Values')
plt.title('Box Plot Comparison')
plt.grid(True, alpha=0.3)
plt.show()

Install with Tessl CLI

npx tessl i tessl/pypi-matplotlib

docs

3d-plotting.md

animation.md

backends.md

colors-styling.md

index.md

object-oriented.md

pyplot.md

shapes.md

tile.json