def __init__(self,width=200,height=150,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) self._add(self,ScatterPlot(),name='chart',validate=None,desc="The main chart") self.chart.width = 115 self.chart.height = 80 self.chart.x = 30 self.chart.y = 40 self.chart.lines[0].strokeColor = color01 self.chart.lines[1].strokeColor = color02 self.chart.lines[2].strokeColor = color03 self.chart.lines[3].strokeColor = color04 self.chart.lines[4].strokeColor = color05 self.chart.lines[5].strokeColor = color06 self.chart.lines[6].strokeColor = color07 self.chart.lines[7].strokeColor = color08 self.chart.lines[8].strokeColor = color09 self.chart.lines[9].strokeColor = color10 self.chart.fillColor = backgroundGrey self.chart.lineLabels.fontName = 'Helvetica' self.chart.xValueAxis.labels.fontName = 'Helvetica' self.chart.xValueAxis.labels.fontSize = 7 self.chart.xValueAxis.forceZero = 0 self.chart.data = [((100,100), (200,200), (250,210), (300,300), (400,500)), ((100,200), (200,300), (250,200), (300,400), (400, 600))] self.chart.xValueAxis.avoidBoundFrac = 1 self.chart.xValueAxis.gridEnd = 115 self.chart.xValueAxis.tickDown = 3 self.chart.xValueAxis.visibleGrid = 1 self.chart.yValueAxis.tickLeft = 3 self.chart.yValueAxis.labels.fontName = 'Helvetica' self.chart.yValueAxis.labels.fontSize = 7 self._add(self,Label(),name='Title',validate=None,desc="The title at the top of the chart") self.Title.fontName = 'Helvetica-Bold' self.Title.fontSize = 7 self.Title.x = 100 self.Title.y = 135 self.Title._text = 'Chart Title' self.Title.maxWidth = 180 self.Title.height = 20 self.Title.textAnchor ='middle' self._add(self,Legend(),name='Legend',validate=None,desc="The legend or key for the chart") self.Legend.colorNamePairs = [(color01, 'Widgets'), (color02, 'Sprockets')] self.Legend.fontName = 'Helvetica' self.Legend.fontSize = 7 self.Legend.x = 153 self.Legend.y = 85 self.Legend.dxTextSpace = 5 self.Legend.dy = 5 self.Legend.dx = 5 self.Legend.deltay = 5 self.Legend.alignment ='right' self.chart.lineLabelFormat = None self.chart.xLabel = 'X Axis' self.chart.y = 30 self.chart.yLabel = 'Y Axis' self.chart.yValueAxis.labelTextFormat = '%d' self.chart.yValueAxis.forceZero = 1 self.chart.xValueAxis.forceZero = 1 self._add(self,0,name='preview',validate=None,desc=None)
def cartesiano(datos): alto = datos["alto"] ancho = datos["ancho"] data = datos["data"] colores = datos["colores"] labels = datos["labels"] menor = datos["rango"][0] mayor = datos["rango"][1] grafico = ScatterPlot() grafico.x = 20 grafico.y = 40 grafico.width = ancho grafico.height = alto grafico.data = data grafico.joinedLines = 1 grafico.lineLabelFormat = None grafico.outerBorderOn = 0 grafico.outerBorderColor = None grafico.background = None for i in range(len(colores)): color = colors.HexColor(colores[i]) grafico.lines[i].strokeColor = color grafico.lines[i].symbol.strokeColor = color grafico.lines[i].symbol.fillColor = color grafico.lines[i].symbol.strokeWidth = 0 grafico.xLabel=labels["x"] grafico.xValueAxis.labels.fontSize = FONTSIZE grafico.xValueAxis.labelTextFormat = lambda x: " Hace\n%d días" % abs(x) grafico.xValueAxis.valueStep = 10 grafico.xValueAxis.labels.dy = -5 grafico.xValueAxis.strokeColor = colors.black grafico.xValueAxis.strokeWidth = 1 grafico.xValueAxis.tickDown = 5 grafico.yLabel=labels["y"] grafico.yValueAxis.labels.fontSize = FONTSIZE grafico.yValueAxis.labelTextFormat = "%d" grafico.yValueAxis.labels.dx = -5 grafico.yValueAxis.strokeColor = colors.black grafico.yValueAxis.strokeWidth = 1 grafico.yValueAxis.tickLeft = 5 grafico.yValueAxis.valueStep = 1 grafico.yValueAxis.valueMin = menor grafico.yValueAxis.valueMax = mayor return crearDrawing(grafico)
def __init__(self,width=400,height=200,*args,**kw): DataAwareDrawing.__init__(*(self,width,height)+args, **kw) self.add(ScatterPlot(),'ScatterPlot') self.ScatterPlot.xValueAxis.labelTextFormat = '%.2f%%' self.ScatterPlot.xLabel="Volatility" self.ScatterPlot.yLabel="% Return" self.ScatterPlot.xValueAxis.labels.fontName = "Helvetica-Oblique" self.ScatterPlot.yValueAxis.labels.fontName = "Helvetica-Oblique" self.width = 175 self.height = 105 self.dataSource = CSVDataSource() self.dataSource.filename = 'scatterplot.csv' self.dataSource.sep = '\t' self.dataSource.integerColumns = ['chartId'] self.dataSource.floatColumns=['Return','Volatility'] self.dataSource.sql = 'SELECT chartId, 100*Return, 100*Volatility FROM scatterplot_data' self.fileNamePattern = 'scatterplot%03d' self.outDir = './output' self.formats = ['eps', 'pdf'] self.ScatterPlot.joinedLines = 0 self.dataSource.associations = Array(2, DataAssociation) self.dataSource.associations.element00 = DataAssociation(column=0, target='chartId', assocType='scalar') self.dataSource.associations.element01 = DataAssociation(column=[[2,1]], target='ScatterPlot.data', assocType='matrix') self.ScatterPlot.lineLabels[(2, 2)].dy = 3
def scatter_plot_2(final_dis_clock, xname, yname): drawing = Drawing(400, 300) chart = ScatterPlot() chart.width = 450 chart.height = 350 chart.x = 32 chart.y = 26 chart.data = [final_dis_clock] chart.joinedLines = 0 chart.fillColor = color03 chart.lineLabelFormat = None chart.lineLabels.fontName = 'Helvetica' lab = Label() lab.setOrigin(130, 260) chart.xValueAxis.avoidBoundFrac = 1 chart.xValueAxis.visibleGrid = 1 chart.xValueAxis.tickDown = 2 chart.xValueAxis.labels.fontName = 'Helvetica' chart.xValueAxis.labels.fontSize = 10 chart.xValueAxis.labelTextFormat = '%d' chart.leftPadding = -32 chart.xLabel = xname chart.xValueAxis.forceZero = 1 chart.yValueAxis.avoidBoundFrac = 1 chart.yValueAxis.visibleGrid = 1 chart.yValueAxis.tickLeft = 2 chart.yValueAxis.labels.fontName = 'Helvetica' chart.yValueAxis.labels.fontSize = 10 chart.yValueAxis.labelTextFormat = '%s' chart.yValueAxis.valueMin = 0.0 chart.yValueAxis.valueStep = 3.0 chart.yValueAxis.valueMax = 9.0 chart.yLabel = yname chart.yLabel.center(10) chart.yValueAxis.forceZero = 0 # Title = Label() # Title.fontName = 'Helvetica-Bold' # Title.fontSize = 10 # Title.x = 100 # Title.y = 550 # Title._text = 'This is just a test chart' # Title.maxWidth = 20 # Title.height = 100 # Title.textAnchor = 'middle' # legend = Legend() # legend.colorNamePairs = [(color01, 'Widgets'), (color02, 'Sprockets')] # legend.fontName = 'Helvetica' # legend.fontSize = 8 # legend.x = 470 # legend.y = 470 # legend.dxTextSpace = 4 # legend.dy = 7 # legend.dx = 7 # legend.deltay = 4 # legend.alignment = 'right' drawing.add(chart) return drawing
def line_chart(data, labels, **kw): """ :param data: contains a three dimensional array of values (list of lists of points) or just a list of datapoint lists (it will be auto-transposed to start at 0) :type data: list :param labels: can contain, but must not ["xlabel", "ylabel", ["data label0", ...]] third item can also be an interger stating the iteration start as label when of same size as data, then a legend is added instead :type lables: ??? :param xlim: limit the x axis to these values, e.g. (0, 100) :type xlim: Tuple(Number, Number) :param ylim: limit the y axis to these values, e.g. (0, 50) :type ylim: Tuple(Number, Number) :param size: size in pixels, e.g. (18*cm, 9*cm) :type size: Tuple(Number, Number) :param title: title of bar chart :type title: string :param lines: list of colors we should use to paint lines :type lines: list[???] :param markers: list of markers we should use to draw markers :type markers: list[`PDF_LINE_MARKERS`,...] :param scatter: weather to do a scatter plot or line chart :type scatter: boolean """ # Get all arguments from the keywordargs title = kw.pop('title', None) scatter = kw.pop('scatter', False) size = kw.pop('plotSize', (18 * cm, 9 * cm)) lines = kw.pop('lines', PDF_CHART_COLORS) markers = kw.pop('markers', PDF_LINE_MARKERS) xlim = kw.pop('xlim', None) ylim = kw.pop('ylim', None) drawing = Drawing(size[0], size[1]) chart = None if(scatter): chart = ScatterPlot() else: chart = LinePlot() for key, val in list(kw.items()): setattr(chart, key, val) if title is not None: drawing.add(String(20, size[1] - 10, title), name='title') chart.y -= 10 chart.width = drawing.width - 20 chart.height = drawing.height - 40 chart.x = 10 chart.y = 10 chart.data = data if type(data[0][0]) in (tuple, list) else [list(zip(list(range(len(i))), i)) for i in data] max_y = 0 min_y = maxsize for i in range(len(data)): chart.lines[i].strokeColor = HexColor(lines[i % len(lines)]) if markers is not None: chart.lines[i].symbol = makeMarker(markers[i % len(markers)]) chart.lines[i].symbol.size = 3 max_y = max([k[1] for k in chart.data[i]] + [max_y]) min_y = min([k[1] for k in chart.data[i]] + [min_y]) chart.yValueAxis.valueMax = max_y * 1.1 chart.yValueAxis.valueMin = min_y * 0.9 chart.xValueAxis.visibleGrid = True chart.yValueAxis.visibleGrid = True if xlim is not None: chart.xValueAxis.valueMin = xlim[0] chart.xValueAxis.valueMax = xlim[1] if ylim is not None: chart.yValueAxis.valueMin = ylim[0] chart.yValueAxis.valueMax = ylim[1] if scatter: chart.xLabel = '' chart.yLabel = '' chart.y -= 10 chart.lineLabelFormat = None if labels is not None: if len(labels) > 0: xlabel = Label() xlabel._text = labels[0] # pylint: disable=W0212 xlabel.textAnchor = 'middle' xlabel.x = drawing.width / 2 xlabel.y = 5 chart.y += 15 drawing.add(xlabel, name="xlabel") if len(labels) > 1: ylabel = Label() ylabel._text = labels[1] # pylint: disable=W0212 xlabel.textAnchor = 'middle' ylabel.angle = 90 ylabel.x = 0 ylabel.y = drawing.height / 2 chart.x += 12 drawing.add(ylabel, name="ylabel") if len(labels) > 2: # when labels are of same size as max nr of data point, use as x axis labels if len(labels[2]) == max([len(x) for x in data]): chart.categoryAxis.categoryNames = labels[2] # pylint: disable=E1101 chart.xValueAxis.labels.angle = 30 # pylint: disable=E1101 # otherwise when integer use the counter elif type(labels[2]) == int: temp = range(labels[2], max([len(x) for x in data]) + labels[2]) chart.categoryAxis.categoryNames = temp # pylint: disable=E1101 # or we could add a legend when of same size as data elif len(labels[2]) == len(data): legend = Legend() chart.height -= 8 chart.y += 8 xlabel.y += 8 legend.boxAnchor = 'sw' legend.x = chart.x + 8 legend.y = -2 legend.columnMaximum = 1 legend.deltax = 50 legend.deltay = 0 legend.dx = 10 legend.dy = 1.5 legend.fontSize = 7 legend.alignment = 'right' legend.dxTextSpace = 5 legend.colorNamePairs = [(HexColor(lines[i]), labels[2][i]) for i in range(len(chart.data))] legend.strokeWidth = 0 drawing.add(legend, name='legend') drawing.add(chart, name='chart') return drawing