Skip to content

Commit

Permalink
improvements to plots
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Oct 14, 2024
1 parent 602a052 commit 051d156
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Bioindustrial-Park
13 changes: 8 additions & 5 deletions benchmark/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def plot_profile(
systems=None, N=3, load=True, save=True
):
if systems is None: systems = list(all_systems)
fs = 10
fs = 12
bst.set_font(fs)
keys = (
'Component flow rate error',
Expand Down Expand Up @@ -817,7 +817,7 @@ def plot_profile(
if n_cols >= 2:
aspect_ratio = 0.75 / 2
elif n_rows == 1:
aspect_ratio = 1.8 / 2
aspect_ratio = 1.4 / 2
else:
aspect_ratio = 1.5 / 2
bst.set_figure_size(aspect_ratio=aspect_ratio, width=width)
Expand Down Expand Up @@ -919,7 +919,7 @@ def plot_profile(
fontsize=fs,
fontweight='bold',
)
index = int(len(tpo) * 0.3)
index = int(len(tpo) * 0.5)
xy = x, y = (tpo[index], ypo[index])
ax.annotate('Phenomena\noriented',
xy=xy,
Expand Down Expand Up @@ -953,15 +953,18 @@ def plot_profile(
# horizontalalignment='center',verticalalignment='center',
# fontsize=fs, fontweight='bold')
left = 0.1
top = 0.85
if n_rows == 2:
bottom = 0.1
elif n_rows == 1:
bottom = 0.15
if n_cols == 1:
left = 0.2
left = 0.25
top = 0.90
bottom = 0.2
else:
bottom = 0.08
plt.subplots_adjust(right=0.96, left=left, bottom=bottom, top=0.85, hspace=0, wspace=0)
plt.subplots_adjust(right=0.96, left=left, bottom=bottom, top=top, hspace=0, wspace=0)
for i in ('svg', 'png'):
name = f'PO_SM_profile.{i}'
file = os.path.join(images_folder, name)
Expand Down
2 changes: 1 addition & 1 deletion biosteam/evaluation/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def evaluate(sample, convergence_model, count=count, **kwargs):

def _reset_system(self):
if self._system is None: return
self._system.empty_recycles()
self._system.empty_outlet_streams()
self._system.reset_cache()

def _failed_evaluation(self):
Expand Down
30 changes: 17 additions & 13 deletions biosteam/plots/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def plot_spearman_2d(rhos, top=None, name=None, color_wheel=None, index=None,
Parameters
----------
rhos : list[pandas.Series]
rhos : list[pandas.Series]|array
Spearman's rank correlation coefficients to be plotted.
top=None : float, optional
Number of parameters to plot (from highest values).
Expand All @@ -676,7 +676,7 @@ def plot_spearman_2d(rhos, top=None, name=None, color_wheel=None, index=None,
rhos = list(reversed(rhos))
if name is None: name = rhos[0].name
if index is None: index = rhos[0].index
values = np.array([i.values for i in rhos])
values = np.array([i.values if hasattr(i, 'values') else i for i in rhos])
indices = list(range(values.shape[-1]))
if cutoff:
cutoff_index, = np.where(np.any(np.abs(rhos) > cutoff, axis=0))
Expand Down Expand Up @@ -931,10 +931,12 @@ def plot_kde(x, y, nbins=100, ax=None, fig=None,
y0 = yticks[0]
yf = yticks[-1]
plt.sca(ax_empty); plt.axis('off')
plt.sca(xbox.axis); plt.axis('off')
plt.xlim([x0, xf])
plt.sca(ybox.axis); plt.axis('off')
plt.ylim([y0, yf])
if xbox:
plt.sca(xbox.axis); plt.axis('off')
plt.xlim([x0, xf])
if ybox:
plt.sca(ybox.axis); plt.axis('off')
plt.ylim([y0, yf])
plt.subplots_adjust(
hspace=0.05, wspace=0.05,
top=0.95, bottom=0.12,
Expand Down Expand Up @@ -1285,6 +1287,7 @@ def color_quadrants(color=None, x=None, y=None, xlim=None, ylim=None,

def label_quadrants(
x=None, y=None, xr=None, yr=None, text=None, color=None,
fs=None,
):
if xr is None:
xrlb = 0
Expand Down Expand Up @@ -1323,36 +1326,36 @@ def label_quadrants(
top_left = f"{p:.0%} {top_left.strip('()')}"
plt.text(xpos(xleft), ypos(ytop), top_left, color=top_left_color,
horizontalalignment='left', verticalalignment='top',
fontsize=8, fontweight='bold', zorder=10)
fontsize=fs, fontweight='bold', zorder=10)
labeled[0] = True
if yub > yrub and xub > xrub and top_right:
if data_given and top_right.endswith('()'):
p = (y_mt_0 & x_mt_0).sum() / y.size
top_right = f"{p:.0%} {top_right.strip('()')}"
plt.text(xpos(xright), ypos(ytop), top_right, color=top_right_color,
horizontalalignment='right', verticalalignment='top',
fontsize=8, fontweight='bold', zorder=10)
fontsize=fs, fontweight='bold', zorder=10)
labeled[1] = True
if ylb < yrlb and xlb < xrlb and bottom_left:
if data_given and bottom_left.endswith('()'):
p = (y_lt_0 & x_lt_0).sum() / y.size
bottom_left = f"{p:.0%} {bottom_left.strip('()')}"
plt.text(xpos(xleft), ypos(ybottom), bottom_left, color=bottom_left_color,
horizontalalignment='left', verticalalignment='bottom',
fontsize=8, fontweight='bold', zorder=10)
fontsize=fs, fontweight='bold', zorder=10)
labeled[2] = True
if ylb < yrlb and xub > xrub and bottom_right:
if data_given and bottom_right.endswith('()'):
p = (y_lt_0 & x_mt_0).sum() / y.size
bottom_right = f"{p:.0%} {bottom_right.strip('()')}"
plt.text(xpos(xright), ypos(ybottom), bottom_right, color=bottom_right_color,
horizontalalignment='right', verticalalignment='bottom',
fontsize=8, fontweight='bold', zorder=10)
fontsize=fs, fontweight='bold', zorder=10)
labeled[3] = True
return labeled

def plot_quadrants(
text, data=None, x=None, y=None, rotate=0,
text, data=None, x=None, y=None, rotate=0, fs=None,
):
quadrant_color = deque([
(*c.CABBI_teal.tint(90).RGBn, 0.9), None,
Expand All @@ -1365,7 +1368,7 @@ def plot_quadrants(
quadrant_color.rotate(rotate)
text_color.rotate(rotate)
labeled_quadrants = format_quadrants(
data, x, y, text, text_color, quadrant_color,
data, x, y, text, text_color, quadrant_color, fs
)
for i, labeled in enumerate(labeled_quadrants):
if labeled: text[i] = '()' if text[i].endswith('()') else None
Expand All @@ -1379,11 +1382,12 @@ def format_quadrants(
text_color=None,
quadrant_color=None,
xlim=None, ylim=None,
fs=None,
):
if data is None: data = (None, None)
color_quadrants(quadrant_color, x, y, xlim, ylim)
return label_quadrants(
*data, x, y, text, text_color,
*data, x, y, text, text_color, fs
)

def add_titles(axes, titles, color):
Expand Down
2 changes: 1 addition & 1 deletion thermosteam

0 comments on commit 051d156

Please sign in to comment.