Skip to main content

A short description of your package

Project description

mpl fold axis

This module provides a function fold_axis to fold axis in matplotlib, which is also called broken axis.

Unlike the example named Broken axis in matplotlib gallery and the brokenaxes package, this module use single axes to realize the broken axis, which is easier to use.

Installation

pip install mpl_fold_axis

Example

Now this module only support linear and log mode, user could use different mode to fold xaxis and yaxis in one axes.

Linear broken axis

import numpy as np
import matplotlib.pyplot as plt

# What user need to do is only import the `fold_axis` function.
from mpl_fold_axis import fold_axis

# Generate data
np.random.seed(19680801)
x = [-31, -30, -29, -1, 0, 1, 29, 30, 31]
y = np.random.randint(0, 50, 9)
y[4] = 172

# Create the figure and the axis
fig, ax = plt.subplots(figsize=(4.5, 3.0))

# Call `Axes.bar` to plot the data
rects = ax.bar(x, y)
ax.bar_label(rects, fmt="%d", padding=2)

# Fold the lower xaxis
# scale (-28, -2) by factor 0.015
# scale (2, 28) by factor 0.015
fold_axis(ax, [(-28, -2, 0.015), (2, 28, 0.015)], axis="x", which="lower")

# Fold both yaxis (lower and upper)
# scale (55, 145) by factor 0.05
fold_axis(ax, [(55, 145, 0.05)], axis="y", which="both")

# Set the ticks and limits
ax.set_xticks(x)
ax.set_yticks([0, 25, 50, 150, 175])
ax.set_ylim(0, 190)

# Enable the grid
ax.grid(True, ls=":")

# Set the labels and title
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_title("Broken Axis Example")

# Add some text and annotations
ax.text(-31, 160, "Text won't be folded")
ax.annotate(
    "The annotate function \ncan be used normally.",
    fontsize=9,
    xy=(1.3, 4),
    xytext=(1.2, 165),
    arrowprops=dict(
        facecolor="black", connectionstyle="arc3,rad=-0.1", arrowstyle="-|>"
    ),
)

plt.show()

Log broken axis

import numpy as np
import matplotlib.pyplot as plt

# What user need to do is only import the `fold_axis` function.
from mpl_fold_axis import fold_axis

x = np.logspace(0, 4, 100)
y = x

fig, ax = plt.subplots(figsize=(4,3))

ax.plot(x, y)

fold_axis(ax, [(600, 4000, 0.1)], mode="log")
# return the lines and rectangles objects.
lines, rectangles = fold_axis(ax, [(600, 4000, 0.1)], axis='y', which='both', mode="log")

ax.set_xticks([1, 10, 100, 500, 5000, 10000],
              [1, 10, 100, 500, 5000, r'$10^4$'])
ax.set_yticks([1, 10, 100, 500, 5000, 10000],
              [1, 10, 100, 500, 5000, r'$10^4$'])


ax.grid(ls=':')
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_title("Broken Axis Example - Log Mode")

plt.show()

Dependencies

matplotlib>=3.6.0, <4.0.0

Changelog

  • 2025-03-29: v0.1.0, first release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpl_fold_axis-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpl_fold_axis-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mpl_fold_axis-0.1.0.tar.gz.

File metadata

  • Download URL: mpl_fold_axis-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mpl_fold_axis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36c86f18bf4ee260510f914c42a6899c54b8ca5975f5052cc746ef307cf01537
MD5 70f5954e4ba500dc59baaecf0f623eae
BLAKE2b-256 9be38e2a7ac83d34a3204936ac9d2e6cc8569f1d78c6ea112d64db023487473a

See more details on using hashes here.

File details

Details for the file mpl_fold_axis-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpl_fold_axis-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mpl_fold_axis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 995d47ecbbb54f9b73319720ac645ef66995e7e5a2a876919396f09972e2383a
MD5 a8b7ced946c75f7c4ccb7b731003e1a5
BLAKE2b-256 12af6059eac0db026ff0ed0f4d98e4ae0f9db179bcef655c61088564a4046679

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page