Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ The `plotLaTeX` package is a recent project to make exporting Python data to a L
<img src="images/example_stbar_plot.png" alt="Fig6" width="1000px">
</p>

**[Stemplot](examples/StemPlot.ipynb)**

<p align="center">
<img src="images/example_stem.png" alt="Fig3" width="1000px">
</p>


**TBD**

- 3D scatter

- Poles Zeros plot

## Installation

Expand Down
8 changes: 8 additions & 0 deletions examples/BarPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@
"source": [
"m_bar.LaTeXcode()"
]
},
{
"cell_type": "markdown",
"id": "1e78a199-71cd-4281-afce-56812b156c98",
"metadata": {},
"source": [
"___"
]
}
],
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions examples/BoxPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@
"source": [
"Bplt.LaTeXcode()"
]
},
{
"cell_type": "markdown",
"id": "a158b8e7-3747-427c-bbfe-2bbf3be0b274",
"metadata": {},
"source": [
"___"
]
}
],
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions examples/HistPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@
"# plot the data using seaborn\n",
"sns.histplot(data=Hplt.data, bins=Hplt.bins)"
]
},
{
"cell_type": "markdown",
"id": "f3a0fd08-5eee-40f0-8ded-8f557e56cff4",
"metadata": {},
"source": [
"___"
]
}
],
"metadata": {
Expand Down
8 changes: 8 additions & 0 deletions examples/LinePlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@
"# save the data as \".csv\" and get the latex figure code\n",
"Lplt.export(f_name=\"line_results.csv\")"
]
},
{
"cell_type": "markdown",
"id": "63aa0ba7-7c63-47da-ba0c-2f28c1bbc674",
"metadata": {},
"source": [
"___"
]
}
],
"metadata": {
Expand Down
186 changes: 186 additions & 0 deletions examples/StemPlot.ipynb

Large diffs are not rendered by default.

Binary file added images/example_stem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/stem_latex_d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion plotLaTeX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
from .hist_plot import HistPlot
from .box_plot import BoxPlot
from .bar_plot import Barplot, MultipleBars
from .stem_plot import StemPlot

__all__ = ["LaTeXplot", "HistPlot", "BoxPlot", "Barplot", "MultipleBars"]
__all__ = ["LaTeXplot", "HistPlot", "BoxPlot", "Barplot", "MultipleBars", "StemPlot"]
75 changes: 75 additions & 0 deletions plotLaTeX/stem_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import numpy as np


class StemPlot:
def __init__(self, layout="default", marker_size=6):
self.layout = layout
self.marker_size = marker_size
self.x_label = "$k$"
self.y_label = "$x[k]$"

def add_xy_vals(self, x_vals, y_vals):
assert len(x_vals) == len(y_vals)
self.x_vals = x_vals
self.y_vals = y_vals

def add_xy_labels(self, x_label, y_label):
self.x_label = x_label
self.y_label = y_label

def LaTeXcode(self, imports=False, caption="Stem plot caption."):
if imports:
print("\tDon´t forget to import the packages:\n")
print(r"\usepackage{graphicx}")
print(r"\usepackage{tikz,pgfplots}")
print("\n*\t*********\n")
print(r"\begin{figure}")
print(r"% definition of stem style")
print(
r"\tikzstyle{stem}=[ycomb,mark=*,mark size="
+ str(self.marker_size)
+ r"\pgflinewidth,color=blue,thick]"
)
print(r"")
print(r" \centering")
print(r" \tikzstyle{every node}=[font=\footnotesize]")
print(r" \begin{tikzpicture}")
print(r" \begin{axis}[")
print(" xlabel={" + self.x_label + "},")
print(" ylabel={" + self.y_label + "},")

if self.layout == "default":
print(r" width=7.5cm,")
print(r" height=3cm,")
print(r" at={(0cm,0cm)},")
print(r" scale only axis,")
print(r" axis background/.style={fill=white},")
print(r" grid=both,")

elif self.layout == "beautiful":
print(r" axis lines=center,")
print(r" xlabel style=right,")
print(r" ylabel style=left,")
print(r" width=7.5cm,")
print(r" height=4cm,")
print(f" ymin={np.min(self.y_vals)-0.5},")
print(f" ymax={np.max(self.y_vals)+1.0},")
print(f" xmin={np.min(self.x_vals)-0.5},")
print(f" xmax={np.max(self.x_vals)+0.5},")
y_ticks = np.arange(np.min(self.y_vals), np.max(self.y_vals))
print(r" xtick={" + ",".join(map(str, self.x_vals)) + "},")
print(r" ytick={" + ",".join(map(str, y_ticks)) + "},")

print(r" grid=both,")
print(r" grid style={dashed,gray!30},")
print(r" axis line style={thick,->},")
print(r" ]")
stem_coords = " ".join(
f"({xi},{yi})" for xi, yi in zip(self.x_vals, self.y_vals)
)
print(r" \addplot[stem] plot coordinates{" + stem_coords + "};")
print(r" \end{axis}")
print(r" \end{tikzpicture}")
print(r" \caption{" + caption + "}")
print(r" \label{fig:" + caption + "}")
print(r"\end{figure}")
Loading