def show(self, ax=None):
r"""Display an image of the transfer function
This function loads up matplotlib and displays the current transfer function.
Parameters
----------
Examples
--------
>>> tf = TransferFunction( (-10.0, -5.0) )
>>> tf.add_gaussian(-9.0, 0.01, 1.0)
>>> tf.show()
"""
from matplotlib import pyplot
from matplotlib.ticker import FuncFormatter
pyplot.clf()
ax = pyplot.axes()
i_data = np.zeros((self.alpha.x.size, self.funcs[0].y.size, 3))
i_data[:,:,0] = np.outer(np.ones(self.alpha.x.size), self.funcs[0].y)
i_data[:,:,1] = np.outer(np.ones(self.alpha.x.size), self.funcs[1].y)
i_data[:,:,2] = np.outer(np.ones(self.alpha.x.size), self.funcs[2].y)
ax.imshow(i_data, origin='lower')
ax.fill_between(np.arange(self.alpha.y.size), self.alpha.x.size * self.alpha.y, y2=self.alpha.x.size, color='white')
ax.set_xlim(0, self.alpha.x.size)
xticks = np.arange(np.ceil(self.alpha.x[0]), np.floor(self.alpha.x[-1]) + 1, 1) - self.alpha.x[0]
xticks *= (self.alpha.x.size-1) / (self.alpha.x[-1] - self.alpha.x[0])
if len(xticks) > 5:
xticks = xticks[::len(xticks)/5]
ax.xaxis.set_ticks(xticks)
def x_format(x, pos):
return "%.1f" % (x * (self.alpha.x[-1] - self.alpha.x[0]) / (self.alpha.x.size-1) + self.alpha.x[0])
ax.xaxis.set_major_formatter(FuncFormatter(x_format))
yticks = np.linspace(0,1,5) * self.alpha.y.size
ax.yaxis.set_ticks(yticks)
def y_format(y, pos):
s = '%0.2f' % ( y )
return s
ax.yaxis.set_major_formatter(FuncFormatter(y_format))
ax.set_ylabel("Opacity")
ax.set_xlabel("Value")
评论列表
文章目录