Add your description here
Project description
consider renaming to matplotickz Consider using jupyter-tickz
Plotickz
A Python library that provides a matplotlib-like API for generating pure TikZ diagrams. Create publication-ready LaTeX figures with familiar matplotlib syntax.
Features
- Familiar API: Uses matplotlib-like functions (
plot(),scatter(),xlabel(), etc.) - Pure TikZ Output: Generates clean TikZ code without external dependencies
- Multiple Plot Types: Line plots, scatter plots, log scales, persistence diagrams, and graph visualizations
- Customizable: Full control over colors, markers, line styles, and more
- LaTeX-Ready: Output can be directly included in LaTeX documents
Installation
pip install plotickz
Or install from source:
git clone https://github.com/yourusername/plotickz.git
cd plotickz
pip install -e .
Quick Start
import plotickz as plz
import numpy as np
# Create data
x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)
# Create plot
plz.figure(figsize=(10, 6))
plz.plot(x, y, color="#2E86AB", linewidth=2, label="sin(x)")
plz.xlabel("x (radians)")
plz.ylabel("y")
plz.title("Sine Wave")
plz.grid(True)
plz.legend()
# Generate TikZ code
tikz_code = plz.show()
print(tikz_code)
# Or save to file
plz.savefig("sine_wave.tex")
API Reference
Figure Management
figure(figsize=(width, height))- Create a new figuregcf()- Get current figuregca()- Get current axes
Plotting Functions
-
plot(x, y, **kwargs)- Create a line plotcolor: Line color (hex or named)linestyle: 'solid', 'dashed', 'dotted', 'dashdot'linewidth: Line width in pointsmarker: Marker style ('o', 's', '^')markersize: Size of markersalpha: Transparency (0-1)label: Legend label
-
scatter(x, y, **kwargs)- Create a scatter plots: Marker sizecolor: Marker colormarker: Marker stylealpha: Transparencyedgecolor: Marker edge coloredgewidth: Marker edge widthlabel: Legend label
Axes Configuration
xlabel(label)- Set x-axis labelylabel(label)- Set y-axis labeltitle(title)- Set plot titlexlim(xmin, xmax)- Set x-axis limitsylim(ymin, ymax)- Set y-axis limitsxscale(scale)- Set x-axis scale ('linear' or 'log')yscale(scale)- Set y-axis scale ('linear' or 'log')grid(visible)- Show/hide gridlegend(loc, visible)- Configure legendaxis(state)- Turn axes on/off
Specialized Plots
persistence_diagram(birth, death, **kwargs)- Create persistence diagramsdraw_nodes(pos, **kwargs)- Draw graph nodesdraw_edges(pos, edges, **kwargs)- Draw graph edgesdraw_triangles(pos, triangles, **kwargs)- Draw filled trianglesdraw_cover(pos, radius, sets, **kwargs)- Draw covers around node sets
Output
show()- Return TikZ code as stringsavefig(filename)- Save TikZ code to file.texfiles include full LaTeX document- Other extensions save raw TikZ code
Examples
Basic Line Plot
import plotickz as plz
import numpy as np
x = np.linspace(0, 2 * np.pi, 50)
y1 = np.sin(x)
y2 = np.cos(x)
plz.figure(figsize=(10, 7))
plz.plot(x, y1, color="#2E86AB", linestyle="solid", linewidth=1.5, label="sin(x)")
plz.plot(x, y2, color="#A23B72", linestyle="dashed", linewidth=1.5, label="cos(x)")
plz.xlabel("x (radians)")
plz.ylabel("y")
plz.title("Trigonometric Functions")
plz.grid(True)
plz.xlim(0, 2 * np.pi)
plz.ylim(-1.5, 1.5)
plz.legend("upper right")
print(plz.show())
Scatter Plot
import plotickz as plz
import numpy as np
np.random.seed(42)
x = np.random.randn(30) * 2 + 5
y = 2 * np.random.randn(30) + 3
plz.figure(figsize=(10, 8))
plz.scatter(x, y, s=30, color="#FF5733", marker="o", alpha=0.7, label="Data points")
plz.xlabel("X values")
plz.ylabel("Y values")
plz.title("Scatter Plot Example")
plz.grid(True)
plz.legend()
print(plz.show())
Combined Plot with Scatter and Line
import plotickz as plz
import numpy as np
np.random.seed(123)
x = np.linspace(0, 10, 20)
y_true = 2 * x + 1
y_measured = y_true + np.random.randn(20) * 2
plz.figure(figsize=(10, 7))
plz.scatter(
x, y_measured, s=50, color="#3498DB", marker="o",
alpha=0.6, label="Measured", edgecolor="#2C3E50", edgewidth=0.8
)
plz.plot(x, y_true, color="#E74C3C", linestyle="solid", linewidth=2, label="True line")
plz.xlabel("X")
plz.ylabel("Y")
plz.title("Linear Fit with Scatter Data")
plz.grid(True)
plz.legend("lower right")
print(plz.show())
Logarithmic Scale Plot
import plotickz as plz
import numpy as np
training_times = np.array([100, 3700, 800, 1200, 500])
fid_scores = np.array([5, 10, 13, 7, 8])
plz.figure(figsize=(10, 7))
plz.xscale("log")
plz.scatter(training_times, fid_scores, s=100, color="#2E86AB", marker="o", alpha=0.8)
x_trend = np.logspace(2, 3.6, 50)
y_trend = 20 - 3 * np.log10(x_trend)
plz.plot(x_trend, y_trend, color="#E74C3C", linestyle="dashed", linewidth=1.5)
plz.xlabel("Training Time with A100 (log-scale)")
plz.ylabel("FID (J)")
plz.title("Training Efficiency - Log Scale X-axis")
plz.grid(True)
plz.xlim(50, 10000)
plz.ylim(0, 25)
print(plz.show())
Log-Log Plot
import plotickz as plz
import numpy as np
x = np.logspace(0, 4, 50)
y = 1000 * x ** (-0.7)
plz.figure(figsize=(10, 7))
plz.xscale("log")
plz.yscale("log")
plz.plot(x, y, color="#E91E63", linestyle="solid", linewidth=2, label="Power Law")
x_points = np.logspace(0.5, 3.5, 10)
y_points = 1000 * x_points ** (-0.7) * (1 + 0.2 * np.random.randn(10))
plz.scatter(x_points, y_points, s=40, color="#9C27B0", alpha=0.7, label="Data")
plz.xlabel("X (log scale)")
plz.ylabel("Y (log scale)")
plz.title("Power Law Relationship")
plz.grid(True)
plz.legend()
print(plz.show())
Persistence Diagram
import plotickz as plz
plz.figure(figsize=(7, 7))
# H_0 features (connected components)
birth_0 = [0, 1.0, 1.5, 0.8, 2.5]
death_0 = [3.5, float("inf"), 2.8, 2.2, float("inf")]
plz.persistence_diagram(birth_0, death_0, color="#5b8def", label="$H_0$")
# H_1 features (loops)
birth_1 = [1.8, 2.2, 3.0]
death_1 = [3.2, 2.5, 4.2]
plz.persistence_diagram(birth_1, death_1, color="#e3773d", label="$H_1$")
# H_2 features (voids)
birth_2 = [2.8, 3.5]
death_2 = [3.5, 4.0]
plz.persistence_diagram(birth_2, death_2, color="#27a165", label="$H_2$")
plz.title("Persistence Diagram")
plz.xlim(-0.5, 5)
plz.ylim(-0.5, 5)
plz.legend()
print(plz.show())
Graph Visualization with Filled Triangle
import plotickz as plz
plz.figure(figsize=(6, 5))
# Node positions
pos = {
"A": (0, 0),
"B": (3, 0),
"C": (1.5, 2.598), # Equilateral triangle
"D": (4.5, 2.598),
}
# Edges
edges = [("A", "B"), ("B", "C"), ("C", "A"), ("B", "D"), ("C", "D")]
# Triangle to fill
triangles = [("A", "B", "C")]
# Draw the graph
plz.draw_triangles(pos, triangles, color="#e63947", alpha=0.2)
plz.draw_edges(pos, edges, width=2, color="#000000")
plz.draw_nodes(
pos, size=20, color="#000000",
labels={k: k for k in pos.keys()}, label_pos="above right"
)
plz.title("Graph with Filled Simplex")
plz.axis("off") # Hide axes for cleaner graph visualization
print(plz.show())
Graph with Covers
import plotickz as plz
plz.figure(figsize=(10, 8))
# Node positions
pos = {
1: (1, 2),
2: (2, 2),
3: (3, 1),
4: (5, 2),
5: (6, 2),
6: (7, 2),
7: (4, 4),
}
# Edges
edges = [(1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (4, 6), (7, 2), (7, 5)]
# Define sets for covers - nodes in same set won't have intersecting covers
cover_sets = [[1, 2, 3], [4, 5, 6], [7]]
# Draw covers first (background)
plz.draw_cover(pos, radius=0.7, sets=cover_sets, color="#14655d", alpha=0.3)
# Draw edges
plz.draw_edges(pos, edges, width=1.0, color="black")
# Draw nodes on top
plz.draw_nodes(pos, size=25, color="black", labels={i: str(i) for i in pos.keys()})
plz.title("Graph with Covers (Scoped by Sets)")
plz.axis("off")
plz.xlim(0, 8)
plz.ylim(0, 5)
print(plz.show())
Output Format
The library generates clean TikZ code that can be:
- Included directly in LaTeX:
\documentclass{article}
\usepackage{tikz}
\begin{document}
% Paste the output from plz.show() here
\end{document}
- Saved as standalone document:
plz.savefig("figure.tex") # Creates compilable LaTeX document
- Integrated into larger documents:
\input{figure.tikz} # Include raw TikZ code
Requirements
- Python 3.6+
- NumPy
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
This library provides a matplotlib-compatible interface for generating TikZ diagrams, making it easy to create publication-quality figures for LaTeX documents.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plotickz-0.1.1.tar.gz.
File metadata
- Download URL: plotickz-0.1.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13dc649f59e323d5ab5f56b4b45195e9b8a0a0846d3cb01e52b83574f119a634
|
|
| MD5 |
c773c948d4b18c5e73e8baff5947de51
|
|
| BLAKE2b-256 |
06a81c0cae885dd67adb4136d3843672535c4d3356b9ef5176648970861dbd1a
|
File details
Details for the file plotickz-0.1.1-py3-none-any.whl.
File metadata
- Download URL: plotickz-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7514df0de8fd2eb2e425bbbe0ebb09e7c89cf91abe84ee2e234fe48dcb7323f7
|
|
| MD5 |
c2edd00174d3ea1f8ec596336c7caebe
|
|
| BLAKE2b-256 |
589683306dc651931ac5fa6f822d9ae035982e3f159e331024ce9748bf42f84f
|