From c24a25b54a575b2219ed28776653357e31ccf780 Mon Sep 17 00:00:00 2001
From: "Michele.Maris" <michele.maris@inaf.it>
Date: Tue, 23 Apr 2024 12:57:11 +0200
Subject: [PATCH] u

---
 src/yapsut/graphics.py | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/yapsut/graphics.py b/src/yapsut/graphics.py
index b17447f..923b50e 100644
--- a/src/yapsut/graphics.py
+++ b/src/yapsut/graphics.py
@@ -1,3 +1,59 @@
+import matplotlib.pyplot as plt
+import numpy as np
+
+class ImshowXT :
+   """ class to handle an improved version of plt.imshow """
+   def __init__(self,matr,x_values,y_values,**kwargs) :
+      """ matr = the matrix to show,
+            x_values = the values on the x axis,
+            y_values, the values on the y axis
+            kwarg = kwargs for plt.imshow
+      """
+      from matplotlib import pyplot as plt
+      self._im=plt.imshow(matr,**kwargs)
+      self._xv=x_values
+      self._yv=y_values
+   def set_xaxis(self,major_values,major_format) :
+      """ format the x axis for a give list of tick values and a formatting string """
+      from matplotlib import pyplot as plt
+      import numpy as np
+      self._mxv=major_values
+      self._mxf=major_format
+      #
+      v=self._xv
+      t=np.array([np.argmin(np.abs(k-v)) for k in major_values])
+      t1=np.arange(len(v))
+      #
+      plt.xticks(t,np.interp(t,t1,v))
+      tt=plt.gca().get_xticklabels()
+      for ik in range(len(tt))  :
+         o=float(tt[ik].get_text())
+         o1=major_format%o
+         tt[ik].set_text(o1)
+      plt.gca().set_xticklabels(tt)
+   def set_yaxis(self,major_values,major_format) :
+      """ format the y axis for a give list of tick values and a formatting string """
+      from matplotlib import pyplot as plt
+      import numpy as np
+      self._myv=major_values
+      self._myf=major_format
+      #
+      v=self._yv
+      t=np.array([np.argmin(np.abs(k-v)) for k in major_values])
+      t1=np.arange(len(v))
+      #
+      plt.yticks(t,np.interp(t,t1,v))
+      tt=plt.gca().get_yticklabels()
+      for ik in range(len(tt))  :
+         o=float(tt[ik].get_text())
+         o1=major_format%o
+         tt[ik].set_text(o1)
+      plt.gca().set_yticklabels(tt)
+   def colorbar(self,**karg) :
+      """ add a color bar """
+      from matplotlib import pyplot as plt
+      plt.colorbar(**karg)
+
 def odot(x,y,color=['yellow','red'],markersize=[30,10],scale=1.,zorder=None,mew=[4,0]) :
    """ draw an odot"""
    from matplotlib import pyplot as plt
-- 
GitLab