Commit 248fbf29 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch 'add-axColorbar' into 'dev'

added axColorbar

See merge request !35
parents cbf818fa 2b07794f
# Import --------------------------------------------------------------
from .. import MyAxes
from .. import numpy as np
from .. import INFO, WARN, SEVR, DBUG, SPCE
# Default values ------------------------------------------------------
_D_ANNOT = "right" # ("right","left","top","bottom",)
# CLASS AxColorBar --------------------------------------------------
class AxColorBar(MyAxes):
# WARNING : because this class is derived from another the keywords of this have to remain untouched
def declareKeywords(self):
self.__class__.__bases__[-1].declareKeywords(self) # crazyness !!!!
self.keywords.update({
'annotation' : _D_ANNOT
})
def bar(self,orientation,levels) :
if type(orientation) == type(str()):
if "vertical".startswith(orientation) :
x = np.array([0, 1])
y = levels
X,Y = np.meshgrid(x, y)
Z = np.array([y,y]).T
elif "horizontal".startswith(orientation):
x = levels
y = np.array([0, 1])
X,Y = np.meshgrid(x, y)
Z = np.array([x,x])
else :
print("orienation not known")
raise UserWarning
else :
print("wrong input type")
raise UserWarning
return X,Y,Z
# Plotting function -------------------------------------------------
def plotting(self):
dmin = self.info4colorBar['min']
dmax = self.info4colorBar['max']
norm = self.info4colorBar['norm']
label = self.info4colorBar['label']
annot = self.keywords["annotation"]
debug = self.fig.debug
if norm == 'lin' :
levels = np.linspace(dmin, dmax, num=100)
elif norm == 'log' :
levels = np.logspace(np.log10(dmin), np.log10(dmax), num=100)
from matplotlib.colors import LogNorm
if annot == "right" :
if(debug): print(DBUG + "Annotation ",annot)
# position
self.yaxis.tick_right()
self.yaxis.set_label_position("right")
if (norm == "lin") :
self.set_yscale("linear", nonposx='clip')
else :
self.set_yscale(norm, nonposx='clip')
# label text
self.xaxis.set_label_text(None)
self.yaxis.set_label_text(label)
# axis visibility
self.xaxis.set_visible(False)
self.yaxis.set_visible(True)
X,Y,Z = self.bar("vert",levels)
elif annot == "left" :
if(debug): print(DBUG + "Annotation ",annot)
# position
self.yaxis.tick_left()
self.yaxis.set_label_position("left")
if (norm == "lin") :
self.set_yscale("linear", nonposx='clip')
else :
self.set_yscale(norm, nonposx='clip')
# label text
self.xaxis.set_label_text(None)
self.yaxis.set_label_text(label)
# axis visibility
self.xaxis.set_visible(False)
self.yaxis.set_visible(True)
X,Y,Z = self.bar("vert",levels)
elif annot == "top" :
# http://stackoverflow.com/questions/14406214/moving-x-axis-to-the-top-of-a-plot-in-matplotlib
if(debug): print(DBUG + "Annotation ",annot)
# position
self.xaxis.tick_top()
self.xaxis.set_label_position("top")
if (norm == "lin") :
self.set_xscale("linear", nonposx='clip')
else :
self.set_xscale(norm, nonposx='clip')
# label text
self.xaxis.set_label_text(label)
self.yaxis.set_label_text(None)
# axis visibility
self.xaxis.set_visible(True)
self.yaxis.set_visible(False)
X,Y,Z = self.bar("horizontal",levels)
elif annot == "bottom" :
if(debug): print(DBUG + "Annotation ",annot)
# position
self.xaxis.tick_bottom()
self.xaxis.set_label_position("bottom")
if (norm == "lin") :
self.set_xscale("linear", nonposx='clip')
else :
self.set_xscale(norm, nonposx='clip')
# label text
self.xaxis.set_label_text(label)
self.yaxis.set_label_text(None)
# axis visibility
self.xaxis.set_visible(True)
self.yaxis.set_visible(False)
X,Y,Z = self.bar("horizontal",levels)
else :
print("Key annotation has no known value")
raise UserWarning
#~ self.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))
if(debug): print(DBUG + "Currently plotting AxColorScale...")
if norm == 'lin' :
self.pcolormesh(X, Y, Z )
elif norm == 'log' :
self.pcolormesh(X, Y, Z ,norm=LogNorm())
# removes white borders around the plot. This is nessessary because MPL likes to clip to round numbers
self.axis('tight')
return(True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment