Skip to content
Snippets Groups Projects
Commit 26fb5fc0 authored by Michele Maris's avatar Michele Maris
Browse files

u

parent c24a25b5
Branches
No related tags found
No related merge requests found
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) :
......@@ -13,17 +10,25 @@ class ImshowXT :
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 """
def set_xaxis(self,major_values,major_format,major_at_nearestPixel=False) :
""" format the x axis for a give list of major tick values and a formatting string
major_at_nearestPixel = True places each major_value at the nearest pixel (default False)
"""
from matplotlib import pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
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))
#
if major_at_nearestPixel :
t=np.array([np.argmin(np.abs(k-v)) for k in major_values])
else :
itp=interp1d(v,t1,fill_value='extrapolate')
t=itp(major_values)
#
plt.xticks(t,np.interp(t,t1,v))
tt=plt.gca().get_xticklabels()
for ik in range(len(tt)) :
......@@ -31,17 +36,25 @@ class ImshowXT :
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 """
def set_yaxis(self,major_values,major_format,major_at_nearestPixel=False) :
""" format the y axis for a give list of major tick values and a formatting string
major_at_nearestPixel = True places each major_value at the nearest pixel (default False)
"""
from matplotlib import pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
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))
#
if major_at_nearestPixel :
t=np.array([np.argmin(np.abs(k-v)) for k in major_values])
else :
itp=interp1d(v,t1,fill_value='extrapolate')
t=itp(major_values)
#
plt.yticks(t,np.interp(t,t1,v))
tt=plt.gca().get_yticklabels()
for ik in range(len(tt)) :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment