From 8ecc7676748c6af9f5083a0b57c6c6cbf2f2eb7d Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Tue, 13 Feb 2018 21:52:01 +0100
Subject: [PATCH] 2D scenarios - drops on interface - falling drop

---
 plot2d.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/plot2d.py b/plot2d.py
index 58a37d68a..43ba8af8b 100644
--- a/plot2d.py
+++ b/plot2d.py
@@ -44,6 +44,30 @@ def scalarField(field, **kwargs):
     return res
 
 
+def scalarFieldAlphaValue(field, color, clip=False, **kwargs):
+    import numpy as np
+    import matplotlib
+    field = np.swapaxes(field, 0, 1)
+    color = matplotlib.colors.to_rgba(color)
+
+    fieldToPlot = np.empty(field.shape + (4,))
+    for i in range(3):
+        fieldToPlot[:, :, i] = color[i]
+
+    if clip:
+        normalizedField = field.copy()
+        normalizedField[normalizedField<0] = 0
+        normalizedField[normalizedField>1] = 1
+    else:
+        min, max = np.min(field), np.max(field)
+        normalizedField = (field - min) / (max - min)
+    fieldToPlot[:, :, 3] = normalizedField
+
+    res = imshow(fieldToPlot, origin='lower', **kwargs)
+    axis('equal')
+    return res
+
+
 def scalarFieldContour(field, **kwargs):
     field = np.swapaxes(field, 0, 1)
     res = contour(field, **kwargs)
-- 
GitLab