You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
3.9 KiB
153 lines
3.9 KiB
import matplotlib.pyplot as plt |
|
import matplotlib.ticker as ticker |
|
import pandas |
|
import pathlib |
|
import seaborn |
|
|
|
from pandas.plotting import register_matplotlib_converters |
|
from collections import namedtuple |
|
|
|
register_matplotlib_converters() |
|
|
|
# set plotting styles |
|
seaborn.set_style("darkgrid") |
|
seaborn.set_style( |
|
"ticks", |
|
{ |
|
"legend.frameon": True, |
|
"xtick.direction": "in", |
|
"ytick.direction": "in", |
|
"axes.linewidth": 2, |
|
}, |
|
) |
|
seaborn.set(rc={"figure.figsize": (12, 6)}) |
|
seaborn.set_context("paper") |
|
|
|
|
|
GraphPaths = namedtuple("GraphPaths", ["environment", "drops"]) |
|
|
|
|
|
def save_plot(data, label, suffix=".png"): |
|
if not suffix.startswith("."): |
|
suffix = f".{suffix}" |
|
folder = data.files.folder |
|
path = folder / f"{folder.name}_{label}{suffix}" |
|
plt.savefig(path) |
|
return path |
|
|
|
|
|
def generate_environment_graph(data): |
|
dataframe = data.print.environment |
|
plt.clf() |
|
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(8.5, 5.8)) |
|
|
|
ax = seaborn.lineplot(data=dataframe["temperature"], ax=axs[0]) |
|
ax.set_ylabel("Temperature [°C]") |
|
ax.set_ylim((10, 40)) |
|
ax.set_xlabel("") |
|
|
|
ax = seaborn.lineplot(data=dataframe["humidity"], ax=axs[1]) |
|
ax.set_ylabel("Humidity [%rH]") |
|
ax.set_ylim((10, 90)) |
|
ax.set_xlabel("Date / Time") |
|
|
|
return save_plot(data, "environment") |
|
|
|
|
|
def _drop_point_plot(df, figure_index, what, y_limit, y_label, colors, hue_order): |
|
ax = seaborn.pointplot( |
|
data=df, |
|
x="well", |
|
y=what, |
|
hue="measurement", |
|
hue_order=hue_order, |
|
style="measurement", |
|
markers=list("X."), |
|
ax=figure_index, |
|
style_order=hue_order[::-1], |
|
palette=colors, |
|
join=False, |
|
) |
|
ax.set_ylim(y_limit) |
|
ax.set_ylabel(y_label) |
|
return ax |
|
|
|
|
|
def _drop_figure_styles(ax): |
|
show_ticks = [] |
|
selected_tick_labels = [] |
|
source_columns = set() |
|
for i, tick_label in enumerate(ax.get_xticklabels()): |
|
well = tick_label.get_text() |
|
column = well[0] |
|
if column not in source_columns: |
|
show_ticks.append(i) |
|
selected_tick_labels.append(well) |
|
source_columns.add(column) |
|
|
|
ax.set_xticks(show_ticks) |
|
ax.set_xticklabels(selected_tick_labels) |
|
ax.xaxis.grid(True) |
|
ax.set_xlabel("") |
|
|
|
|
|
def _make_drop_figure(*args): |
|
ax = _drop_point_plot(*args) |
|
_drop_figure_styles(ax) |
|
|
|
|
|
def generate_drop_graph(data, nozzle): |
|
# select the data of the nozlle |
|
selection = data.drops["nozzle"] == nozzle |
|
nozzle_df = data.drops[selection] |
|
sorted_df = nozzle_df.sort_values(by="when", ascending=True) |
|
|
|
# setup some parameters |
|
colors = seaborn.palettes.color_palette() |
|
hue_order = ["pre run", "post run"] |
|
palette = {"pre run": colors[1], "post run": colors[0]} |
|
settings = data.print.graph_settings |
|
|
|
plt.clf() |
|
# figsize looks strange, but is fittet for pdf report |
|
fig, axs = plt.subplots(nrows=3, sharex=True, figsize=(8.75, 8.75)) |
|
|
|
_make_drop_figure( |
|
sorted_df, |
|
axs[0], |
|
"distance", |
|
(settings.distance.min, settings.distance.max), |
|
settings.distance.label, |
|
palette, |
|
hue_order, |
|
) |
|
_make_drop_figure( |
|
sorted_df, |
|
axs[1], |
|
"offset", |
|
(settings.offset.min, settings.offset.max), |
|
settings.offset.label, |
|
palette, |
|
hue_order, |
|
) |
|
_make_drop_figure( |
|
sorted_df, |
|
axs[2], |
|
"volume", |
|
(settings.volume.min, settings.volume.max), |
|
settings.volume.label, |
|
palette, |
|
hue_order, |
|
) |
|
axs[-1].set_xlabel("Print Solution Well") |
|
|
|
return save_plot(data, f"nozzle_{nozzle}") |
|
|
|
|
|
def generate_all_graphs(data): |
|
env_graph = generate_environment_graph(data) |
|
|
|
nozzles = data.drops["nozzle"].unique() |
|
drop_graphs = {n: generate_drop_graph(data, n) for n in nozzles} |
|
|
|
return GraphPaths(env_graph, drop_graphs)
|
|
|