Example #1
0
    def __init__(self, *args, **kwargs):
        if len(args) == 1:
            self.xvalues, self.yvalues = meshgrid(arange(args[0].shape[0]),
                                                  arange(args[0].shape[1]))
            self.zvalues = args[0]
        else:
            self.xvalues, self.yvalues, self.zvalues = args

        # shading
        self.shading = kwargs.get('shading', None)

        # custom plot options
        self.pgf_options = kwargs.get('pgf_options', [])

        # catch common mistakes
        if not isinstance(self.pgf_options, list):
            raise TypeError('pgf_options should be a list.')

        # add plot to axis
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)

        # adjust default behavior for 3D plots
        self.axes.axis_on_top = False
        self.axes.xlabel_near_ticks = False
        self.axes.ylabel_near_ticks = False
        self.axes.zlabel_near_ticks = False
Example #2
0
File: plot.py Project: cshen/pypgf
	def __init__(self, *args, **kwargs):
		"""
		Initializes plot properties.
		"""

		# data points
		if len(args) < 1:
			self.xvalues = asarray([])
			self.yvalues = asarray([])
		elif len(args) < 2:
			self.yvalues = asarray(args[0]).flatten()
			self.xvalues = arange(1, len(self.yvalues) + 1)
		else:
			self.xvalues = asarray(args[0]).flatten()
			self.yvalues = asarray(args[1]).flatten()

		# line style
		self.line_style = kwargs.get('line_style', None)
		self.line_width = kwargs.get('line_width', None)
		self.opacity = kwargs.get('opacity', None)
		self.color = kwargs.get('color', None)

		self.fill = kwargs.get('fill', False)

		# marker style
		self.marker = kwargs.get('marker', None)
		self.marker_size = kwargs.get('marker_size', None)
		self.marker_edge_color = kwargs.get('marker_edge_color', None)
		self.marker_face_color = kwargs.get('marker_face_color', None)
		self.marker_opacity = kwargs.get('marker_opacity', None)

		# error bars
		self.xvalues_error = asarray(kwargs.get('xvalues_error', [])).flatten()
		self.yvalues_error = asarray(kwargs.get('yvalues_error', [])).flatten()
		self.error_marker = kwargs.get('error_marker', None)
		self.error_color = kwargs.get('error_color', None)
		self.error_style = kwargs.get('error_style', None)
		self.error_width = kwargs.get('error_width', None)

		# comb (or stem) plots
		self.ycomb = kwargs.get('ycomb', False)
		self.xcomb = kwargs.get('xcomb', False)

		self.closed = kwargs.get('closed', False)

		self.const_plot = kwargs.get('const_plot', False)

		# legend entry for this plot
		self.legend_entry = kwargs.get('legend_entry', None)

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# add plot to axes
		self.axes = kwargs.get('axis', Axes.gca())
		self.axes.children.append(self)
Example #3
0
	def __init__(self, *args, **kwargs):
		if len(args) == 1:
			self.xvalues, self.yvalues = meshgrid(
				arange(args[0].shape[0]),
				arange(args[0].shape[1]))
			self.zvalues = args[0]
		else:
			self.xvalues, self.yvalues, self.zvalues = args

		# shading
		self.shading = kwargs.get('shading', None)

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# add plot to axis
		self.axes = kwargs.get('axes', Axes.gca())
		self.axes.children.append(self)

		# adjust default behavior for 3D plots
		self.axes.axis_on_top = False
		self.axes.xlabel_near_ticks = False
		self.axes.ylabel_near_ticks = False
		self.axes.zlabel_near_ticks = False
Example #4
0
	def __init__(self, *args, **kwargs):
		# legend entries
		self.legend_entries = args

		# legend properties
		self.at = kwargs.get('at', None)
		self.anchor = kwargs.get('anchor', None)
		self.location = kwargs.get('location', None)
		self.align = kwargs.get('align', 'left')
		self.box = kwargs.get('box', True)
		self.font_size = kwargs.get('font_size', None)

		# assign legend to axis
		self.axes = kwargs.get('axes', Axes.gca())
		self.axes.legend = self
Example #5
0
File: image.py Project: cshen/pypgf
	def __init__(self, image, **kwargs):
		"""
		@type  image: string/array_like/PIL Image
		@param image: a filepath or an image in grayscale or RGB

		@param vmin:

		@param vmax:

		@param cmap:
		"""

		self.cmap = kwargs.get('cmap', 'gray')

		if isinstance(image, str):
			self.image = PILImage.open(image)

		elif isinstance(image, PILImage.Image):
			self.image = image.copy()

		else:
			if isinstance(image, ndarray):
				# copy array
				image = array(image)

				if image.dtype.kind != 'i':
					vmin = kwargs.get('vmin', min(image))
					vmax = kwargs.get('vmax', max(image))

					# rescale image
					image = (image - vmin) / (vmax - vmin)
					image = array(image * 256., dtype='int32')

				image[image < 0] = 0
				image[image > 255] = 255
				image = array(image, dtype='uint8')

				if image.ndim < 3:
					image = repeat(image.reshape(image.shape[0], -1, 1), 3, 2)

			self.image = PILImage.fromarray(image)

		# add image to axis
		self.axes = kwargs.get('axis', Axes.gca())
		self.axes.children.append(self)

		self.idx = Image._counter
		Image._counter += 1
Example #6
0
    def __init__(self, x, y, text, **kwargs):
        self.x = x
        self.y = y
        self.text = text

        # properties
        self.color = kwargs.get('color', None)

        # custom plot options
        self.pgf_options = kwargs.get('pgf_options', [])

        # catch common mistakes
        if not isinstance(self.pgf_options, list):
            raise TypeError('pgf_options should be a list.')

        # add text to axes
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)
Example #7
0
    def __init__(self, x, y, r, **kwargs):
        self.x = x
        self.y = y
        self.r = r

        # properties
        self.color = kwargs.get('color', None)
        self.line_style = kwargs.get('line_style', None)
        self.line_width = kwargs.get('line_width', None)

        # custom plot options
        self.pgf_options = kwargs.get('pgf_options', [])

        # catch common mistakes
        if not isinstance(self.pgf_options, list):
            raise TypeError('pgf_options should be a list.')

        # add rectangle to axes
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)
Example #8
0
	def __init__(self, x, y, r, **kwargs):
		self.x = x
		self.y = y
		self.r = r

		# properties
		self.color = kwargs.get('color', None)
		self.line_style = kwargs.get('line_style', None)
		self.line_width = kwargs.get('line_width', None)

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# add rectangle to axes
		self.axes = kwargs.get('axes', Axes.gca())
		self.axes.children.append(self)
Example #9
0
File: arrow.py Project: cshen/pypgf
	def __init__(self, x, y, dx, dy, **kwargs):
		self.x = x
		self.y = y
		self.dx = dx
		self.dy = dy

		# properties
		self.color = kwargs.get('color', None)
		self.arrow_style = kwargs.get('arrow_style', '-latex')
		self.line_style = kwargs.get('line_style', None)

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# add arrow to axes
		self.axes = kwargs.get('axis', Axes.gca())
		self.axes.children.append(self)
Example #10
0
    def __init__(self, *args, **kwargs):
        # data points
        if len(args) < 1:
            self.xvalues = asarray([])
            self.yvalues = asarray([])
        elif len(args) < 2:
            self.yvalues = asarray(args[0]).reshape(shape(args[0])[0], -1)
            self.xvalues = arange(1, self.yvalues.shape[-1] + 1)
        else:
            self.xvalues = asarray(args[0]).flatten()
            self.yvalues = asarray(args[1]).reshape(shape(args[1])[0], -1)

        self.box_width = kwargs.get('box_width', 0.5)

        # custom plot options
        self.pgf_options = kwargs.get('pgf_options', [])

        # catch common mistakes
        if not isinstance(self.pgf_options, list):
            raise TypeError('pgf_options should be a list.')

        # add plot to axes
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)
Example #11
0
	def __init__(self, *args, **kwargs):
		# data points
		if len(args) < 1:
			self.xvalues = asarray([])
			self.yvalues = asarray([])
		elif len(args) < 2:
			self.yvalues = asarray(args[0]).reshape(shape(args[0])[0], -1)
			self.xvalues = arange(1, self.yvalues.shape[-1] + 1)
		else:
			self.xvalues = asarray(args[0]).flatten()
			self.yvalues = asarray(args[1]).reshape(shape(args[1])[0], -1)

		self.box_width = kwargs.get('box_width', 0.5);

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# add plot to axes
		self.axes = kwargs.get('axis', Axes.gca())
		self.axes.children.append(self)
Example #12
0
def gca():
	"""
	Returns currently active axis.
	"""

	return Axes.gca()
Example #13
0
	def __init__(self, image, **kwargs):
		"""
		@type  image: string/array_like/PIL Image
		@param image: a filepath or an image in grayscale or RGB

		@param vmin:

		@param vmax:

		@param cmap:

		@param xmin:
		@param xmax:
		@param ymin:
		@param ymax:

		@param limits:
		"""

		self._cmap = kwargs.get('cmap', 'gray')

		if isinstance(image, str):
			self.image = PILImage.open(image)

		elif isinstance(image, PILImage.Image):
			self.image = image.copy()

		else:
			if isinstance(image, ndarray):
				# copy array
				image = array(image)

				if image.dtype.kind not in ['u', 'i']:
					self.vmin = kwargs.get('vmin', min(image))
					self.vmax = kwargs.get('vmax', max(image))

					# rescale image
					image = (image - self.vmin) / (self.vmax - self.vmin)
					image = array(image * 256., dtype='int32')

				image[image < 0] = 0
				image[image > 255] = 255
				image = array(image, dtype='uint8')

				if image.ndim < 3:
					image = repeat(image.reshape(image.shape[0], -1, 1), 3, 2)
					for i in range(image.shape[0]):
						for j in range(image.shape[1]):
							image[i, j, :] = colormaps[self._cmap][image[i, j, 0]]

			self.image = PILImage.fromarray(image)

		# specify pixel coordinates 
		self.xmin = kwargs.get('xmin', 0)
		self.xmax = kwargs.get('xmax', self.image.size[0])
		self.ymin = kwargs.get('ymin', 0)
		self.ymax = kwargs.get('ymax', self.image.size[1])

		if 'limits' in kwargs:
			self.xmin, self.xmax, \
			self.ymin, self.ymax = kwargs['limits']

		# add image to axis
		self.axes = kwargs.get('axes', Axes.gca())
		self.axes.children.append(self)

		self.idx = Image._counter
		Image._counter += 1
Example #14
0
    def __init__(self, image, **kwargs):
        """
		@type  image: string/array_like/PIL Image
		@param image: a filepath or an image in grayscale or RGB

		@param vmin:

		@param vmax:

		@param cmap:

		@param xmin:
		@param xmax:
		@param ymin:
		@param ymax:

		@param limits:
		"""

        self._cmap = kwargs.get('cmap', 'gray')

        if isinstance(image, str):
            self.image = PILImage.open(image)

        elif isinstance(image, PILImage.Image):
            self.image = image.copy()

        else:
            if isinstance(image, ndarray):
                # copy array
                image = array(image)

                if image.dtype.kind not in ['u', 'i']:
                    self.vmin = kwargs.get('vmin', min(image))
                    self.vmax = kwargs.get('vmax', max(image))

                    # rescale image
                    image = (image - self.vmin) / (self.vmax - self.vmin)
                    image = array(image * 256., dtype='int32')

                image[image < 0] = 0
                image[image > 255] = 255
                image = array(image, dtype='uint8')

                if image.ndim < 3:
                    image = repeat(image.reshape(image.shape[0], -1, 1), 3, 2)
                    for i in range(image.shape[0]):
                        for j in range(image.shape[1]):
                            image[i, j, :] = colormaps[self._cmap][image[i, j,
                                                                         0]]

            self.image = PILImage.fromarray(image)

        # specify pixel coordinates
        self.xmin = kwargs.get('xmin', 0)
        self.xmax = kwargs.get('xmax', self.image.size[0])
        self.ymin = kwargs.get('ymin', 0)
        self.ymax = kwargs.get('ymax', self.image.size[1])

        if 'limits' in kwargs:
            self.xmin, self.xmax, \
            self.ymin, self.ymax = kwargs['limits']

        # add image to axis
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)

        self.idx = Image._counter
        Image._counter += 1
Example #15
0
    def __init__(self, *args, **kwargs):
        """
		Initializes plot properties.
		"""

        # data points
        if len(args) < 1:
            self.xvalues = asarray([])
            self.yvalues = asarray([])
        elif len(args) < 2:
            self.yvalues = asarray(args[0]).flatten()
            self.xvalues = arange(1, len(self.yvalues) + 1)
        else:
            self.xvalues = asarray(args[0]).flatten()
            self.yvalues = asarray(args[1]).flatten()

        # labels for each data point
        self.labels = kwargs.get('labels', None)

        if isinstance(self.labels, str):
            self.labels = [self.labels]

        if self.labels and len(self.labels) != len(self.xvalues):
            raise ValueError(
                'The number of labels should correspond to the number of data points.'
            )

        # line style
        self.line_style = kwargs.get('line_style', None)
        self.line_width = kwargs.get('line_width', None)
        self.opacity = kwargs.get('opacity', None)
        self.color = kwargs.get('color', None)

        self.fill = kwargs.get('fill', False)

        # marker style
        self.marker = kwargs.get('marker', None)
        self.marker_size = kwargs.get('marker_size', None)
        self.marker_edge_color = kwargs.get('marker_edge_color', None)
        self.marker_face_color = kwargs.get('marker_face_color', None)
        self.marker_opacity = kwargs.get('marker_opacity', None)

        # error bars
        self.xvalues_error = asarray(kwargs.get('xvalues_error', [])).flatten()
        self.yvalues_error = asarray(kwargs.get('yvalues_error', [])).flatten()
        self.error_marker = kwargs.get('error_marker', None)
        self.error_color = kwargs.get('error_color', None)
        self.error_style = kwargs.get('error_style', None)
        self.error_width = kwargs.get('error_width', None)

        # PGF pattern to fill area and bar plots
        self.pattern = kwargs.get('pattern', None)

        # comb (or stem) plots
        self.ycomb = kwargs.get('ycomb', False)
        self.xcomb = kwargs.get('xcomb', False)

        self.closed = kwargs.get('closed', False)

        self.const_plot = kwargs.get('const_plot', False)

        # legend entry for this plot
        self.legend_entry = kwargs.get('legend_entry', None)

        # custom plot options
        self.pgf_options = kwargs.get('pgf_options', [])

        # catch common mistakes
        if not isinstance(self.pgf_options, list):
            raise TypeError('pgf_options should be a list.')

        # comment LaTeX code
        self.comment = kwargs.get('comment', '')

        # add plot to axes
        self.axes = kwargs.get('axes', Axes.gca())
        self.axes.children.append(self)
Example #16
0
	def __init__(self, *args, **kwargs):
		"""
		Initializes plot properties.
		"""

		# data points
		if len(args) < 1:
			self.xvalues = asarray([])
			self.yvalues = asarray([])
		elif len(args) < 2:
			self.yvalues = asarray(args[0]).flatten()
			self.xvalues = arange(1, len(self.yvalues) + 1)
		else:
			self.xvalues = asarray(args[0]).flatten()
			self.yvalues = asarray(args[1]).flatten()

		# labels for each data point
		self.labels = kwargs.get('labels', None)

		if isinstance(self.labels, str):
			self.labels = [self.labels]

		if self.labels and len(self.labels) != len(self.xvalues):
			raise ValueError('The number of labels should correspond to the number of data points.')

		# line style
		self.line_style = kwargs.get('line_style', None)
		self.line_width = kwargs.get('line_width', None)
		self.opacity = kwargs.get('opacity', None)
		self.color = kwargs.get('color', None)

		self.fill = kwargs.get('fill', False)

		# marker style
		self.marker = kwargs.get('marker', None)
		self.marker_size = kwargs.get('marker_size', None)
		self.marker_edge_color = kwargs.get('marker_edge_color', None)
		self.marker_face_color = kwargs.get('marker_face_color', None)
		self.marker_opacity = kwargs.get('marker_opacity', None)

		# error bars
		self.xvalues_error = asarray(kwargs.get('xvalues_error', [])).flatten()
		self.yvalues_error = asarray(kwargs.get('yvalues_error', [])).flatten()
		self.error_marker = kwargs.get('error_marker', None)
		self.error_color = kwargs.get('error_color', None)
		self.error_style = kwargs.get('error_style', None)
		self.error_width = kwargs.get('error_width', None)

		# PGF pattern to fill area and bar plots
		self.pattern = kwargs.get('pattern', None)

		# comb (or stem) plots
		self.ycomb = kwargs.get('ycomb', False)
		self.xcomb = kwargs.get('xcomb', False)

		self.closed = kwargs.get('closed', False)

		self.const_plot = kwargs.get('const_plot', False)

		# legend entry for this plot
		self.legend_entry = kwargs.get('legend_entry', None)

		# custom plot options
		self.pgf_options = kwargs.get('pgf_options', [])

		# catch common mistakes
		if not isinstance(self.pgf_options, list):
			raise TypeError('pgf_options should be a list.')

		# comment LaTeX code
		self.comment = kwargs.get('comment', '')

		# add plot to axes
		self.axes = kwargs.get('axes', Axes.gca())
		self.axes.children.append(self)
Example #17
0
def gca():
    """
	Returns currently active axis.
	"""

    return Axes.gca()