A simple diagram drawing tool
Project description
SimpleDiagramTool
SimpleDiagramTool
is a Python class that provides a simple interface for creating diagrams using matplotlib. It allows you to add blocks, lines, and arrows to a diagram, and then display the diagram.
Installation
This tool requires matplotlib to be installed. You can install it using pip:
pip install matplotlib
Usage
First, import the SimpleDiagramTool
class:
from simple_diagram_tool import SimpleDiagramTool
Then, create an instance of the class, specifying the length and width of the diagram:
diagram = SimpleDiagramTool(10, 10)
Adding a block
You can add a block to the diagram using the add_block
method. This method takes the following parameters:
position
: A tuple(x, y)
specifying the bottom left corner of the block.size
: A tuple(width, height)
specifying the size of the block.label
: A string label for the block.boundary_color
: (optional) The color of the block boundary. Default is 'r' (red).text_size
: (optional) The size of the label text. Default is 10.
diagram.add_block((1, 1), (2, 2), 'Block 1', boundary_color='b', text_size=12)
Adding a line
You can add a line to the diagram using the add_line
method. This method takes the following parameters:
start_pos
: A tuple(x, y)
specifying the start position of the line.end_pos
: A tuple(x, y)
specifying the end position of the line.line_color
: (optional) The color of the line. Default is 'k' (black).
diagram.add_line((1, 1), (3, 3), line_color='g')
Adding an arrow
You can add an arrow to the diagram using the add_arrow
method. This method takes the following parameters:
start_pos
: A tuple(x, y)
specifying the start position of the arrow.end_pos
: A tuple(x, y)
specifying the end position of the arrow.arrow_color
: (optional) The color of the arrow. Default is 'k' (black).
diagram.add_arrow((1, 1), (3, 3), arrow_color='r')
Displaying the diagram
Finally, you can display the diagram using the show
method:
diagram.show()
Error Handling
If you try to add an element that is out of the bounds of the diagram, a ValueError
will be raised. Make sure that all elements fit within the specified length and width of the diagram.
Examples
Here's a complete example that creates a diagram with a block, a line, and an arrow:
from simple_diagram_tool import SimpleDiagramTool
diagram = SimpleDiagramTool(10, 10)
diagram.add_block((1, 1), (2, 2), 'Block 1', boundary_color='b', text_size=12)
diagram.add_line((1, 1), (3, 3), line_color='g')
diagram.add_arrow((1, 1), (3, 3), arrow_color='r')
diagram.show()
This will create a 10x10 diagram with a blue block labeled 'Block 1' at position (1, 1) with size (2, 2), a green line from (1, 1) to (3, 3), and a red arrow from (1, 1) to (3, 3).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Gh0stSimpleDiagramTool-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 327ad1f2e4afc63ae8f97a38e06ec54192be4dc8711457ed8823704c3f5bbc7f |
|
MD5 | 9cfa1195655cc1d70afd3e39620b6034 |
|
BLAKE2b-256 | 5ef71d51deadf77c56c7c0d6ba84de1bbbd67643c538a949237cef9f97bbf184 |
Hashes for Gh0stSimpleDiagramTool-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 753bec8ad3c7a7c23c0c5d24b066e9fe11175bbae344fa347b0fe7f0dadcfee0 |
|
MD5 | 9d0fa8668e777bfb83118fed6db3f51d |
|
BLAKE2b-256 | c4810f1b2b2575bda8cd7bd8ca360b0b225cd6465125b0b16c8c67e32244ef7f |