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

u

parent 41b61451
No related branches found
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) :
""" 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]) : def odot(x,y,color=['yellow','red'],markersize=[30,10],scale=1.,zorder=None,mew=[4,0]) :
""" draw an odot""" """ draw an odot"""
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment