icplot 0.0.6__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {icplot-0.0.6/src/icplot.egg-info → icplot-0.0.7}/PKG-INFO +4 -2
- {icplot-0.0.6 → icplot-0.0.7}/pyproject.toml +5 -3
- icplot-0.0.7/src/icplot/graph/__init__.py +1 -0
- icplot-0.0.7/src/icplot/graph/plot.py +200 -0
- {icplot-0.0.6 → icplot-0.0.7/src/icplot.egg-info}/PKG-INFO +4 -2
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot.egg-info/SOURCES.txt +3 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot.egg-info/requires.txt +3 -1
- icplot-0.0.7/test/test_line_plots.py +26 -0
- {icplot-0.0.6 → icplot-0.0.7}/LICENSE +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/README.md +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/setup.cfg +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/__init__.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/cairo_interface.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/gantt.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/geometry.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/image_utils.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/main_cli.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/project_elements.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot/tex_interface.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot.egg-info/dependency_links.txt +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot.egg-info/entry_points.txt +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/src/icplot.egg-info/top_level.txt +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/test/test_cairo_interface.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/test/test_gantt_chart.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/test/test_image_utils.py +0 -0
- {icplot-0.0.6 → icplot-0.0.7}/test/test_tex_interface.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: icplot
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Utilities for generating plots and graphics for technical reports.
|
|
5
5
|
Author-email: "James Grogan, Irish Centre for High End Computing" <james.grogan@ichec.ie>
|
|
6
6
|
Project-URL: Repository, https://git.ichec.ie/performance/toolshed/icplot
|
|
@@ -16,13 +16,15 @@ Description-Content-Type: text/markdown
|
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
Requires-Dist: wand
|
|
18
18
|
Requires-Dist: matplotlib
|
|
19
|
-
Requires-Dist: iccore==0.0.
|
|
19
|
+
Requires-Dist: iccore==0.0.9
|
|
20
20
|
Provides-Extra: test
|
|
21
21
|
Requires-Dist: pytest; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-cov; extra == "test"
|
|
23
23
|
Requires-Dist: pytest-sugar; extra == "test"
|
|
24
24
|
Requires-Dist: black; extra == "test"
|
|
25
25
|
Requires-Dist: mypy; extra == "test"
|
|
26
|
+
Requires-Dist: flake8; extra == "test"
|
|
27
|
+
Requires-Dist: pylint; extra == "test"
|
|
26
28
|
Provides-Extra: cairo
|
|
27
29
|
Requires-Dist: pycairo; extra == "cairo"
|
|
28
30
|
Requires-Dist: CairoSVG; extra == "cairo"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "icplot"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.7"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="James Grogan, Irish Centre for High End Computing", email="james.grogan@ichec.ie" },
|
|
6
6
|
]
|
|
@@ -18,7 +18,7 @@ keywords = ["Publishing", "Technical Reports", "Graphics"]
|
|
|
18
18
|
|
|
19
19
|
dependencies = ["wand",
|
|
20
20
|
"matplotlib",
|
|
21
|
-
"iccore==0.0.
|
|
21
|
+
"iccore==0.0.9"]
|
|
22
22
|
|
|
23
23
|
[project.urls]
|
|
24
24
|
Repository = "https://git.ichec.ie/performance/toolshed/icplot"
|
|
@@ -30,7 +30,9 @@ test = [
|
|
|
30
30
|
"pytest-cov",
|
|
31
31
|
"pytest-sugar",
|
|
32
32
|
"black",
|
|
33
|
-
"mypy"
|
|
33
|
+
"mypy",
|
|
34
|
+
"flake8",
|
|
35
|
+
"pylint"
|
|
34
36
|
]
|
|
35
37
|
|
|
36
38
|
cairo = [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .plot import * # NOQA
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module has content for generating plots
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import cast
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
|
12
|
+
import matplotlib # NOQA
|
|
13
|
+
|
|
14
|
+
matplotlib.use("Agg")
|
|
15
|
+
import matplotlib.pyplot as plt # NOQA
|
|
16
|
+
import matplotlib as mpl # NOQA
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PlotSeries:
|
|
20
|
+
|
|
21
|
+
def __init__(self, label: str = ""):
|
|
22
|
+
self.label = label
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class LinePlotSeries(PlotSeries):
|
|
26
|
+
def __init__(self, x: list[float], y: list[float], label: str = "") -> None:
|
|
27
|
+
super().__init__(label)
|
|
28
|
+
self.x = x
|
|
29
|
+
self.y = y
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class MatplotlibPlotter:
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.ax = plt.subplot(111)
|
|
36
|
+
|
|
37
|
+
def set_decorations(self, x_label, y_label, title, x_ticks, y_ticks):
|
|
38
|
+
self.ax.legend(loc="upper left")
|
|
39
|
+
if x_label:
|
|
40
|
+
self.ax.set_xlabel(x_label)
|
|
41
|
+
if y_label:
|
|
42
|
+
self.ax.set_ylabel(y_label)
|
|
43
|
+
if title:
|
|
44
|
+
self.ax.set_title(title)
|
|
45
|
+
if x_ticks:
|
|
46
|
+
self.ax.set_xticks(x_ticks)
|
|
47
|
+
if y_ticks:
|
|
48
|
+
self.ax.set_yticks(y_ticks)
|
|
49
|
+
|
|
50
|
+
def plot_line(self, x, y, label, color):
|
|
51
|
+
self.ax.plot(x, y, label=label, color=color)
|
|
52
|
+
|
|
53
|
+
def render(self, path: Path | None = None):
|
|
54
|
+
if path:
|
|
55
|
+
plt.savefig(path)
|
|
56
|
+
else:
|
|
57
|
+
plt.show()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Plot:
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
title: str = "",
|
|
64
|
+
x_label: str = "",
|
|
65
|
+
y_label: str = "",
|
|
66
|
+
legend_label: str = "",
|
|
67
|
+
) -> None:
|
|
68
|
+
self.series: list[PlotSeries] = []
|
|
69
|
+
self.title = title
|
|
70
|
+
self.plot_type = ""
|
|
71
|
+
self.x_label = x_label
|
|
72
|
+
self.y_label = y_label
|
|
73
|
+
self.legend_label = legend_label
|
|
74
|
+
self.c_map = mpl.colormaps["viridis"]
|
|
75
|
+
self.x_ticks = None
|
|
76
|
+
self.y_ticks = None
|
|
77
|
+
self.impl = MatplotlibPlotter()
|
|
78
|
+
|
|
79
|
+
def get_colour(self, curr, values, c_map):
|
|
80
|
+
"""
|
|
81
|
+
Returns a colour based on a cmap and how far across
|
|
82
|
+
the datasets you are
|
|
83
|
+
"""
|
|
84
|
+
length = len(values)
|
|
85
|
+
position = curr / length
|
|
86
|
+
return c_map(0.25 + (position / 2))
|
|
87
|
+
|
|
88
|
+
def set_colour_map(self, cmap="viridis"):
|
|
89
|
+
self.c_map = mpl.colormaps[cmap]
|
|
90
|
+
|
|
91
|
+
def set_x_ticks(self, lower, upper, step):
|
|
92
|
+
self.x_ticks = range(lower, upper + 1, step)
|
|
93
|
+
|
|
94
|
+
def set_y_ticks(self, lower, upper, step):
|
|
95
|
+
self.y_ticks = range(lower, upper + 1, step)
|
|
96
|
+
|
|
97
|
+
def set_decorations(self):
|
|
98
|
+
self.impl.set_decorations(
|
|
99
|
+
self.x_label, self.y_label, self.title, self.x_ticks, self.y_ticks
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def plot(self, path: Path | None = None):
|
|
103
|
+
raise NotImplementedError()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class LinePlot(Plot):
|
|
107
|
+
|
|
108
|
+
def plot(self, path: Path | None = None):
|
|
109
|
+
|
|
110
|
+
first = True
|
|
111
|
+
for i, series in enumerate(self.series):
|
|
112
|
+
colour = self.get_colour(i, self.series, self.c_map)
|
|
113
|
+
label = f"{series.label}"
|
|
114
|
+
if first and self.legend_label:
|
|
115
|
+
label = f"{label} {self.legend_label}"
|
|
116
|
+
first = False
|
|
117
|
+
line_series = cast(LinePlotSeries, series)
|
|
118
|
+
self.impl.plot_line(line_series.x, line_series.y, label=label, color=colour)
|
|
119
|
+
|
|
120
|
+
self.set_decorations()
|
|
121
|
+
self.impl.render(path)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class MultiFigureLinePlotter:
|
|
125
|
+
"""
|
|
126
|
+
Plot with multiple figures. Each is a line plot
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
def __init__(self, data: dict, figures: list, xlabel: str) -> None:
|
|
130
|
+
self.data = data
|
|
131
|
+
self.figures = figures
|
|
132
|
+
self.size: tuple = (10, 5)
|
|
133
|
+
self.xlabel = xlabel
|
|
134
|
+
self.output_fmt = "svg"
|
|
135
|
+
|
|
136
|
+
def _plot_line(self, key: str, label: str):
|
|
137
|
+
plt.plot(self.data[key], label=label)
|
|
138
|
+
|
|
139
|
+
def _decorate(self, ylabel: str, title: str):
|
|
140
|
+
plt.title(title)
|
|
141
|
+
plt.xlabel(self.xlabel)
|
|
142
|
+
plt.ylabel(ylabel)
|
|
143
|
+
plt.legend()
|
|
144
|
+
plt.show()
|
|
145
|
+
|
|
146
|
+
def plot(self, output_path: Path):
|
|
147
|
+
"""
|
|
148
|
+
Do the plot
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
for idx, figure_info in enumerate(self.figures):
|
|
152
|
+
plt.figure(figsize=self.size)
|
|
153
|
+
|
|
154
|
+
for data_key, label in zip(figure_info["keys"], figure_info["labels"]):
|
|
155
|
+
self._plot_line(data_key, label)
|
|
156
|
+
|
|
157
|
+
title = figure_info["title"]
|
|
158
|
+
ylabel = figure_info["ylabel"]
|
|
159
|
+
|
|
160
|
+
self._decorate(ylabel, title)
|
|
161
|
+
plt.savefig(str(output_path) + f"_{idx}.{self.output_fmt}")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class DatasetGridPlotter:
|
|
165
|
+
"""
|
|
166
|
+
Plot a dataset on a grid. A dataset has pairs of images corresponding
|
|
167
|
+
to an image and an associated mask.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
def __init__(
|
|
171
|
+
self, title: str = "", stride: int = 4, size: tuple = (25, 20)
|
|
172
|
+
) -> None:
|
|
173
|
+
self.title = title
|
|
174
|
+
self.stride = stride
|
|
175
|
+
self.size = size
|
|
176
|
+
|
|
177
|
+
def _plot_grid_element(self, rows: int, cols: int, count: int, image, transform):
|
|
178
|
+
plt.subplot(rows, cols, count)
|
|
179
|
+
if transform:
|
|
180
|
+
plt.imshow(transform.reverse(image.squeeze(0).float()))
|
|
181
|
+
else:
|
|
182
|
+
plt.imshow(image.squeeze(0).float())
|
|
183
|
+
plt.axis("off")
|
|
184
|
+
plt.title(self.title)
|
|
185
|
+
return count + 1
|
|
186
|
+
|
|
187
|
+
def plot(self, data, num_samples: int, output_path: Path, transform=None):
|
|
188
|
+
plt.figure(figsize=self.size)
|
|
189
|
+
rows = num_samples // self.stride
|
|
190
|
+
cols = num_samples // rows
|
|
191
|
+
count = 1
|
|
192
|
+
indices = [random.randint(0, len(data) - 1) for _ in range(num_samples)]
|
|
193
|
+
|
|
194
|
+
for index in indices:
|
|
195
|
+
if count == num_samples + 1:
|
|
196
|
+
break
|
|
197
|
+
x, y = data[index]
|
|
198
|
+
count = self._plot_grid_element(rows, cols, count, x, transform)
|
|
199
|
+
count = self._plot_grid_element(rows, cols, count, y, transform)
|
|
200
|
+
plt.savefig(output_path)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: icplot
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Utilities for generating plots and graphics for technical reports.
|
|
5
5
|
Author-email: "James Grogan, Irish Centre for High End Computing" <james.grogan@ichec.ie>
|
|
6
6
|
Project-URL: Repository, https://git.ichec.ie/performance/toolshed/icplot
|
|
@@ -16,13 +16,15 @@ Description-Content-Type: text/markdown
|
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
Requires-Dist: wand
|
|
18
18
|
Requires-Dist: matplotlib
|
|
19
|
-
Requires-Dist: iccore==0.0.
|
|
19
|
+
Requires-Dist: iccore==0.0.9
|
|
20
20
|
Provides-Extra: test
|
|
21
21
|
Requires-Dist: pytest; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-cov; extra == "test"
|
|
23
23
|
Requires-Dist: pytest-sugar; extra == "test"
|
|
24
24
|
Requires-Dist: black; extra == "test"
|
|
25
25
|
Requires-Dist: mypy; extra == "test"
|
|
26
|
+
Requires-Dist: flake8; extra == "test"
|
|
27
|
+
Requires-Dist: pylint; extra == "test"
|
|
26
28
|
Provides-Extra: cairo
|
|
27
29
|
Requires-Dist: pycairo; extra == "cairo"
|
|
28
30
|
Requires-Dist: CairoSVG; extra == "cairo"
|
|
@@ -16,7 +16,10 @@ src/icplot.egg-info/dependency_links.txt
|
|
|
16
16
|
src/icplot.egg-info/entry_points.txt
|
|
17
17
|
src/icplot.egg-info/requires.txt
|
|
18
18
|
src/icplot.egg-info/top_level.txt
|
|
19
|
+
src/icplot/graph/__init__.py
|
|
20
|
+
src/icplot/graph/plot.py
|
|
19
21
|
test/test_cairo_interface.py
|
|
20
22
|
test/test_gantt_chart.py
|
|
21
23
|
test/test_image_utils.py
|
|
24
|
+
test/test_line_plots.py
|
|
22
25
|
test/test_tex_interface.py
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from icplot.graph import LinePlot, LinePlotSeries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_line_plot():
|
|
7
|
+
|
|
8
|
+
plot = LinePlot(title="test",
|
|
9
|
+
x_label="test_x",
|
|
10
|
+
y_label="test_y",
|
|
11
|
+
legend_label="test_legend")
|
|
12
|
+
|
|
13
|
+
data = [([0, 5, 10], [1, 2, 3]),
|
|
14
|
+
([0, 5, 10], [3, 6, 9]),
|
|
15
|
+
([0, 5, 10], [4, 8, 12])]
|
|
16
|
+
|
|
17
|
+
for idx, [x, y] in enumerate(data):
|
|
18
|
+
plot.series.append(LinePlotSeries(x, y, label=f"Series {idx}"))
|
|
19
|
+
|
|
20
|
+
plot.set_x_ticks(0, 10, 5)
|
|
21
|
+
|
|
22
|
+
output_path = Path() / "output.svg"
|
|
23
|
+
plot.plot(output_path)
|
|
24
|
+
|
|
25
|
+
assert output_path.exists()
|
|
26
|
+
output_path.unlink()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|