Skip to main content

package to draw boxes in 2d plots

Project description

easyshapey

PyPI version License: MIT

A tool for manipulating 2D shapes in plots. Select data points, create arbitrary polygons, and visualize shapes on matplotlib axes.

Installation

pip install easyshapey

Or from source:

pip install git+https://github.com/caganze/easyshapey.git

Features

  • Box: Rectangular shapes fitted to data trends
  • RotatedBox: Auto-rotated boxes minimizing bounding area
  • Oval: Elliptical shapes fitted to data
  • Polygon: Arbitrary N-sided polygons (triangles to any N)

All shapes support:

  • Data point selection (select())
  • Point containment checking (contains())
  • Rotation (rotate())
  • Plotting on matplotlib axes (plot())

Quick Start

Box

import numpy as np
import pandas as pd
from easyshapey import Box

# Create data
x = np.random.random(100)
y = 2 * x + np.random.normal(0, 0.2, 100)
data = np.array([x, y])

# Fit box to data
box = Box()
box.data = data

# Select points inside
selected = box.select(data)

# Plot
box.plot()

Polygon

from easyshapey import Polygon

# Create triangle
tri = Polygon(vertices=[(0, 0), (1, 0), (0.5, 1)])
print(f"Sides: {tri.n_sides}, Area: {tri.area:.2f}")

# Create any N-sided polygon
hexagon = Polygon(vertices=[
    (1, 0), (0.5, 0.87), (-0.5, 0.87),
    (-1, 0), (-0.5, -0.87), (0.5, -0.87)
])

# Check point containment
inside = tri.contains([(0.5, 0.3)])  # [True]

# Rotate 45 degrees
tri.rotate(np.pi / 4)

Interactive Polygon Creation

from easyshapey import Polygon

# Click points on figure, press 'q' when done
poly = Polygon.from_clicks(min_points=3)

Polygon from Data

from easyshapey import Polygon
import numpy as np

data = np.random.rand(2, 50)  # 50 random points

# Bounding box
bbox = Polygon.from_data(data, method='bounding_box')

# Convex hull (requires scipy)
hull = Polygon.from_data(data, method='convex_hull')

Selector

from easyshapey import Box, Selector

# Combine multiple shapes
box1 = Box()
box1.data = data1

box2 = Box()
box2.data = data2

selector = Selector()
selector.shapes = [box1, box2]
selector.logic = 'and'  # or 'or'

# Select points in all shapes
result = selector.select()

API Reference

Polygon

Property Description
n_sides Number of sides
vertices List of (x, y) tuples
center Centroid (x, y)
area Area (shoelace formula)
angle First edge angle (radians)
Method Description
contains(points) Check if points inside
select(data) Select data points inside
rotate(angle) Rotate around center
plot(**kwargs) Plot on matplotlib axes
from_clicks() Create interactively
from_data() Create from data points

Box

Property Description
vertices Corner vertices
center Center (x, y)
area Bounding area
coeffs Fitted line [slope, intercept]

Examples

See the tutorial notebook for more examples.


Changelog

[0.0.4] - 2025-01-07

Added

  • Polygon class: arbitrary N-sided 2D polygons
  • Interactive creation via Polygon.from_clicks()
  • Data fitting via Polygon.from_data()
  • Comprehensive test suite

Changed

[0.0.3] - 2025-01-07

Security

  • Fixed deprecated pandas .ix[] with .loc[]
  • Updated security policy

[0.0.2] - 2022-05-04

  • Version bump and package updates

[0.0.1] - 2022-01-27

  • Initial release

Security

Supported Versions

Version Supported
0.0.4
0.0.3
< 0.0.3

Reporting Vulnerabilities

Email: caganze@gmail.com

Include: description, reproduction steps, impact, suggested fix.

Response time: 48 hours acknowledgment, 7 days initial assessment.


License

MIT License

Author

caganze - caganze@gmail.com

Links

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

easyshapey-0.0.5.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

easyshapey-0.0.5-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file easyshapey-0.0.5.tar.gz.

File metadata

  • Download URL: easyshapey-0.0.5.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for easyshapey-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6733cfaabd94c8470c03df8d08c8e6a5e84e71c332541384442541b21fda6290
MD5 8669fb1ede5c97485aa11eb434c9cfd7
BLAKE2b-256 8f54b470c012f5e9a5be045a3093601d4996b58a78f25c35a9ceedc7419a8941

See more details on using hashes here.

File details

Details for the file easyshapey-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: easyshapey-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for easyshapey-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 56367d3e79fea95ee9c5e1caa7f63f517cf0ff25896d34bf746aa9259875efc0
MD5 7d3ec398e5876b807d251fe5bd7545f0
BLAKE2b-256 975ced7ae28c79b2215dae2d2b81b5d8a5c5ca51cb9b42658af247b6901db885

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