Skip to main content

Matplotlib figure dock based on QT6

Project description

MDock

A Python package for creating dockable matplotlib figures using PyQt6. MDock provides a professional docking interface where matplotlib figures can be dynamically arranged, resized, and managed as draggable dock widgets.

Overview

MDock integrates matplotlib's figure rendering capabilities with PyQt6's powerful docking system (via PyQt6Ads). This allows you to create sophisticated multi-figure applications where figures can be:

  • Docked and undocked - freely arrange figure windows
  • Organized in layouts - organize multiple figures in a tabbed or side-by-side interface
  • Saved and restored - persist window layouts between sessions
  • Controlled programmatically - manage figures from Python with a simple API

Installation

Install MDock using pip:

pip install mdock

Requirements

  • Python 3.9 or higher
  • matplotlib
  • PyQt6Ads

Quick Start

import matplotlib.pyplot as plt
import mdock

# Set the dock window title (optional)
mdock.title("My Application")

# Create some matplotlib figures
fig1, ax1 = plt.subplots()
ax1.plot([1, 2, 3, 4], [1, 4, 2, 3])
ax1.set_title("Figure 1")

fig2, ax2 = plt.subplots()
ax2.scatter([1, 2, 3, 4], [1, 4, 2, 3])
ax2.set_title("Figure 2")

Features

  • Docking Interface: Dock multiple matplotlib figures in a professional Qt interface
  • Persistent Layouts: Save and restore dock configurations between sessions
  • Toolbar Controls: Built-in toolbar for managing dock states
  • Easy API: Simple functions for common operations

API Reference

Module Functions

show()

Display the MDock window containing all docked figures.

import mdock
mdock.show()

drawnow()

Redraw all canvas figures in the dock and flush events. Use this to update all visible plots.

import mdock
mdock.drawnow()

title(t)

Set the title of the MDock window.

Parameters:

  • t (str): The window title
import mdock
mdock.title("My Dock Window")

store_state()

Save the current dock layout, window geometry, and perspective to persistent storage.

import mdock
mdock.store_state()

restore_state()

Restore the previously saved dock layout and window geometry.

import mdock
mdock.restore_state()

Usage Examples

Example 1: Basic Multi-Figure Application

import matplotlib.pyplot as plt
import mdock

# Set window title
mdock.title("Data Visualization")

# Create multiple figures
for i in range(3):
    fig, ax = plt.subplots(num=f'Data Visualization number {i+1}')
    ax.plot(range(10), [x**i for x in range(10)])
    ax.set_title(f"Plot {i+1}")

Example 2: Saving and Restoring Layouts

import matplotlib.pyplot as plt
import mdock

# Create some plots
fig1, ax1 = plt.subplots(num="Plot 1")
ax1.plot([1, 2, 3], [1, 2, 3])

fig2, ax2 = plt.subplots(num="Plot 2")
ax2.plot([1, 2, 3], [3, 2, 1])

# Show the docking interface
mdock.show()

# Restore previous layout (after figures are created). 
# If a layout for these figures has been saved, it will be restored.
mdock.restore_state()

# (...)

# Later, after manually modifying the figure layout, save the current layout
mdock.store_state()

Example 3: Real-time Updates

import matplotlib.pyplot as plt
import mdock
import numpy as np

# Enable interactive mode
plt.ion()

# Plot data interactively - updates appear immediately
for i in range(100):
    plt.figure("My Real-Time Plot")
    plt.clf()
    x = np.linspace(0, 10, 100)
    y = np.sin(x + i/10)
    plt.plot(x, y)   
    # Update the plot     
    mdock.drawnow()

Notes

  • Dock perspectives and window geometry are stored using Qt's QSettings, which automatically uses the appropriate storage location for your OS (Registry on Windows, plist on macOS, etc.)
  • The MDock class uses class variables to maintain a single shared docking interface across all figures
  • The first time a figure is created, the MDock window and docking manager are initialized
  • Toolbar buttons allow manual storage and restoration of dock states

License

MIT License - See LICENSE file for details

Author

Mikkel N. Schmidt (mnsc@dtu.dk)

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

mdock-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

mdock-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file mdock-0.1.1.tar.gz.

File metadata

  • Download URL: mdock-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mdock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9239fd609a3e4f3cef78e5a1abbc8b0f34411365f86373b3e082a1de4208812a
MD5 9ad748a82d5ad5652965602d33897253
BLAKE2b-256 39549d174df7e860061c5ebb7f190891337bd5f4af990c24df96d621c76dba40

See more details on using hashes here.

File details

Details for the file mdock-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mdock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mdock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 759a2146c9474dcce8ad2c4aa54168e9855d94e1ce4ce4972819111bb1ac98a4
MD5 ae47303f2b668f5904dd30b854e91a2a
BLAKE2b-256 19c680a8253ec09eb83ce30a2f22a025e334ac923a5dea3af13afa3b65ea0aa9

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