本文整理汇总了Python中reportlab.graphics.charts.legends.Legend.y方法的典型用法代码示例。如果您正苦于以下问题:Python Legend.y方法的具体用法?Python Legend.y怎么用?Python Legend.y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.charts.legends.Legend
的用法示例。
在下文中一共展示了Legend.y方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addAutoLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def addAutoLegend(self,chart,offset,num,side='bottom'):
from reportlab.lib.validators import Auto
width = 300
height = 150
legend = Legend()
if side == 'bottom':
legend.x = offset[0]-15
legend.dx = 20
legend.dy = 5
legend.y = offset[1]-25
legend.deltax = None
legend.autoXPadding = 35
legend.deltay = 5
legend.boxAnchor = 'nw'
legend.dxTextSpace = 5
legend.columnMaximum = (num/3)
if num%3 >0:
legend.columnMaximum += 1
legend.variColumn = True
elif side == 'right':
legend.x = offset[0]+offset[2]+40
legend.dx = 20
legend.dy = 5
legend.y = offset[1]+offset[3]-15
legend.deltax = None
legend.deltay = 5
legend.boxAnchor = 'nw'
legend.dxTextSpace = 5
legend.columnMaximum = 9
legend.colorNamePairs=Auto(chart=chart)
return legend
示例2: autoLegender
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def autoLegender(i,chart,styleObj,sym='symbol'):
if sym:
setattr(styleObj[0],sym, makeMarker('Diamond',size=6))
setattr(styleObj[1],sym,makeMarker('Square'))
width = 300
height = 150
legend = Legend()
legend.x = width-5
legend.y = 5
legend.dx = 20
legend.dy = 5
legend.deltay = 0
legend.boxAnchor = 'se'
if i=='col auto':
legend.colorNamePairs[0]=(Auto(chart=chart),'auto chart=self.chart')
legend.colorNamePairs[1]=(Auto(obj=chart,index=1),'auto chart=self.chart index=1')
elif i=='full auto':
legend.colorNamePairs=Auto(chart=chart)
elif i=='swatch set':
legend.swatchMarker=makeMarker('Circle')
legend.swatchMarker.size = 10
elif i=='swatch auto':
legend.swatchMarker=Auto(chart=chart)
d = Drawing(width,height)
d.background = Rect(0,0,width,height,strokeWidth=1,strokeColor=colors.red,fillColor=None)
m = makeMarker('Cross')
m.x = width-5
m.y = 5
m.fillColor = colors.red
m.strokeColor = colors.yellow
d.add(chart)
d.add(legend)
d.add(m)
return d
示例3: legend_draw
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def legend_draw(self, labels, chart, **kwargs):
legend = Legend()
chart_type = kwargs['type']
legend.fontName = 'FreeSans'
legend.fontSize = 13
legend.strokeColor = None
if 'x' in kwargs:
legend.x = kwargs['x']
if 'y' in kwargs:
legend.y = kwargs['y']
legend.alignment = 'right'
if 'boxAnchor' in kwargs:
legend.boxAnchor = kwargs['boxAnchor']
if 'columnMaximum' in kwargs:
legend.columnMaximum = kwargs['columnMaximum']
# x-distance between neighbouring swatche\s
legend.deltax = 0
lcolors = legendcolors
if chart_type == 'line':
lcolors = [colors.red, colors.blue]
legend.colorNamePairs = zip(lcolors, labels)
for i, color in enumerate(lcolors):
if chart_type == 'line':
chart.lines[i].fillColor = color
elif chart_type == 'pie':
chart.slices[i].fillColor = color
elif chart_type == 'bar':
chart.bars[i].fillColor = color
return legend
示例4: sample4pie
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def sample4pie():
width = 300
height = 150
d = Drawing(width, height)
pc = Pie()
pc.x = 150
pc.y = 50
pc.data = [1, 50, 100, 100, 100, 100, 100, 100, 100, 50]
pc.labels = ["0", "a", "b", "c", "d", "e", "f", "g", "h", "i"]
pc.slices.strokeWidth = 0.5
pc.slices[3].popout = 20
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2, 2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)
legend = Legend()
legend.x = width - 5
legend.y = height - 5
legend.dx = 20
legend.dy = 5
legend.deltax = 0
legend.boxAnchor = "nw"
legend.colorNamePairs = Auto(chart=pc)
d.add(legend)
return d
示例5: make_legend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def make_legend(self, drawing, chart):
if not self.legend_labels:
return
# Get legend labels
labels = self.get_legend_labels()
# Legend object
legend = Legend()
legend.colorNamePairs = zip(self.colors[:len(labels)], labels)
legend.columnMaximum = len(legend.colorNamePairs)
legend.deltay = 5
legend.alignment = 'right'
legend.x = drawing.width + 40
legend.y = drawing.height - (self.title and self.title.get('height', DEFAULT_TITLE_HEIGHT) or 0)
# Sets legend extra attributes if legend_labels is a dictionary
if isinstance(self.legend_labels, dict):
for k,v in self.legend_labels.items():
if k != 'labels' and v:
setattr(legend, k, v)
drawing.add(legend)
return legend
示例6: sample4pie
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def sample4pie():
width = 300
height = 150
d = Drawing(width, height)
pc = Pie()
pc.x = 150
pc.y = 50
pc.data = [1, 50, 100, 100, 100, 100, 100, 100, 100, 50]
pc.labels = ['0','a','b','c','d','e','f','g','h','i']
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 20
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)
legend = Legend()
legend.x = width-5
legend.y = height-5
legend.dx = 20
legend.dy = 5
legend.deltax = 0
legend.boxAnchor = 'nw'
legend.colorNamePairs=Auto(chart=pc)
d.add(legend)
return d
示例7: __add_graph
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def __add_graph(self):
drawing = Drawing(200, 100)
data = list()
labels = list()
self.c.drawString(370, 730,
'Distribucion en pesos'.encode('utf-8'))
for acc in self.accounts:
balance = acc.balance
if acc.currency == 'USD':
balance = balance * self.dolar
data.append(balance)
labels.append(acc.name)
pie = Pie()
pie.x = 280
pie.y = 630
pie.height = 100
pie.width = 100
pie.data = data
pie.labels = labels
pie.simpleLabels = 1
pie.slices.strokeWidth = 1
pie.slices.strokeColor = black
pie.slices.label_visible = 0
legend = Legend()
legend.x = 400
legend.y = 680
legend.dx = 8
legend.dy = 8
legend.fontName = 'Helvetica'
legend.fontSize = 7
legend.boxAnchor = 'w'
legend.columnMaximum = 10
legend.strokeWidth = 1
legend.strokeColor = black
legend.deltax = 75
legend.deltay = 10
legend.autoXPadding = 5
legend.yGap = 0
legend.dxTextSpace = 5
legend.alignment = 'right'
legend.dividerLines = 1|2|4
legend.dividerOffsY = 4.5
legend.subCols.rpad = 30
n = len(pie.data)
self.__setItems(n,pie.slices,
'fillColor',self.pdf_chart_colors)
legend.colorNamePairs = [(pie.slices[i].fillColor,
(pie.labels[i][0:20],'$%0.2f' % pie.data[i])) for i in xrange(n)]
drawing.add(pie)
drawing.add(legend)
x, y = 0, 0
renderPDF.draw(drawing, self.c, x, y, showBoundary=False)
示例8: autoLegender
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def autoLegender(i, chart, styleObj, sym="symbol"):
if sym:
setattr(styleObj[0], sym, makeMarker("Diamond", size=6))
setattr(styleObj[1], sym, makeMarker("Square"))
width = 300
height = 150
legend = Legend()
legend.x = width - 5
legend.y = 5
legend.dx = 20
legend.dy = 5
legend.deltay = 0
legend.boxAnchor = "se"
if i == "col auto":
legend.colorNamePairs[0] = (Auto(chart=chart), "auto chart=self.chart")
legend.colorNamePairs[1] = (Auto(obj=chart, index=1), "auto chart=self.chart index=1")
elif i == "full auto":
legend.colorNamePairs = Auto(chart=chart)
elif i == "swatch set":
legend.swatchMarker = makeMarker("Circle")
legend.swatchMarker.size = 10
elif i == "swatch auto":
legend.swatchMarker = Auto(chart=chart)
d = Drawing(width, height)
d.background = Rect(0, 0, width, height, strokeWidth=1, strokeColor=colors.red, fillColor=None)
m = makeMarker("Cross")
m.x = width - 5
m.y = 5
m.fillColor = colors.red
m.strokeColor = colors.yellow
d.add(chart)
d.add(legend)
d.add(m)
return d
示例9: createReadsHistogram
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def createReadsHistogram(self):
'''
Routine to create histogram of numbers of 'reads' for given years
'''
# The vertical bar chart will get added to the 'drawing' object
drawing = Drawing(400, 200)
# Now we can start constructing the vertical bar chart
lc = VerticalBarChart()
lc.x = 30
lc.y = 50
lc.height = 125
lc.width = 350
# Record the years, because these values will be used as x axis labels
years = sorted(map(lambda b: int(b), filter(lambda a: a.isdigit(), self.data['reads histogram'].keys())))
# This list will hold the data points for the histogram
lc.data = []
# Record the counts of both reads of refereed and non-refereed papers
refereed = []
non_refereed = []
# The maximum number of reads will be used to scale the y axis
max_reads = 0
# Take only the first two values of each value string in the histogram data
# The first is for 'all' papers, the second for the 'refereed' papers
for year in years:
values = map(lambda a: int(a),self.data['reads histogram'][str(year)].split(':')[:2])
max_reads = max(max_reads,max(values))
refereed.append(values[1])
non_refereed.append(values[0]-values[1])
lc.data.append(refereed)
lc.data.append(non_refereed)
# Proper label placement for years: shift by (-6, -6) in x and y to have labels positioned properly
lc.categoryAxis.labels.dx = -6
lc.categoryAxis.labels.dy = -6
# and rotate the labels by 90 degrees
lc.categoryAxis.labels.angle = 90
# Define the value step and maximum for the y axis
lc.valueAxis.valueMax = int(math.ceil(float(max_reads)/10.0))*10
lc.valueAxis.valueStep = max(int(math.floor(float(max_reads)/10.0)),1)
lc.valueAxis.valueMin = 0
# The label names are the access years
lc.categoryAxis.categoryNames = map(lambda a: str(a), years)
# Now add the histogram to the 'drawing' object
drawing.add(lc)
# Add a legend to the histogram so that we now which color means what
legend = Legend()
legend.alignment = 'right'
legend.x = 380
legend.y = 160
legend.deltax = 60
legend.dxTextSpace = 10
items = [(colors.red, 'refereed'), (colors.green, 'non-refereed')]
legend.colorNamePairs = items
drawing.add(legend, 'legend')
# Finally add a title to the histogram
drawing.add(String(200,190,"reads histogram", textAnchor="middle", fillColor='blue'))
# Append the result to the 'story'
self.story.append(drawing)
示例10: setLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def setLegend(self):
legend = Legend()
legend.colorNamePairs = []
legend.fontName = 'Helvetica-Bold'
legend.fontSize = 12
legend.x = 100
legend.y = 110
legend.dxTextSpace = 5
legend.dy = 20
legend.dx = 20
legend.deltay = 5
legend.deltax = 7
legend.columnMaximum = 1
legend.alignment ='right'
legend.x = 60
legend.y = 50
legend.columnMaximum = 2
legend.colorNamePairs = []
legend.colorNamePairs.append((colors.green,
self._data_dict['max_score_legend']))
legend.colorNamePairs.append((colors.red,
self._data_dict['score_legend']))
self.add(legend, name='Legend')
示例11: myBarLegend
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def myBarLegend(drawing, name1, name2):
"Add sample swatches to a diagram."
d = drawing or Drawing(400, 200)
swatches = Legend()
swatches.alignment = 'right'
swatches.x = 80
swatches.y = 160
swatches.deltax = 60
swatches.dxTextSpace = 10
swatches.columnMaximum = 4
items = [(colors.blue, name1), (colors.lightblue, name2)]
swatches.colorNamePairs = items
d.add(swatches, 'legend')
return d
示例12: __init__
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def __init__(self, data, labels):
super(PieChart, self).__init__(400,200)
colors = [
HexColor("#0000e5"),
HexColor("#ff0011"),
HexColor("#800000"),
HexColor("#e05897"),
HexColor("#a08ff7"),
HexColor("#8f8ff5"),
HexColor("#c7c7fa"),
HexColor("#800000"),
HexColor("#eb8585"),
HexColor("#d60a0a"),
HexColor("#ffff00"),
HexColor("#1f1feb"),
]
# Create pie chart
pieChart = Pie()
pieChart.x = 40
pieChart.y = 30
pieChart.width = 120
pieChart.height = 120
pieChart.slices.strokeWidth=0.5
data = json.loads(data)
pieChart.data = data
pieChart.labels = []
labels = json.loads(labels.replace("'",'"'))
for d in data:
pieChart.labels.append(str(d))
# Create legend
legend = Legend()
legend.x = 380
legend.y = 60
legend.boxAnchor = 'se'
legend.subCols[1].align = 'right'
legend.colorNamePairs = []
len_data = len(data)
for i in range(0,len_data):
pieChart.slices[i].fillColor = colors[i]
legend.colorNamePairs.append((colors[i],labels[i]))
self.add(pieChart, "pie chart")
self.add(legend, "legend")
示例13: sample3
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def sample3(drawing=None):
"Add sample swatches to a diagram."
d = drawing or Drawing(400, 200)
swatches = Legend()
swatches.alignment = 'right'
swatches.x = 80
swatches.y = 160
swatches.deltax = 60
swatches.dxTextSpace = 10
swatches.columnMaximum = 4
items = [(colors.red, 'before'), (colors.green, 'after')]
swatches.colorNamePairs = items
d.add(swatches, 'legend')
return d
示例14: create_single_grade_pdf
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
def create_single_grade_pdf(grade,content_area_id):
'''--Variables--'''
school_level = []
Story=[]
Elements=[]
contentarea_name = ""
buff = StringIO()
formatted_time = time.ctime()
minimum = 100
standard_averages=[[]]
standard_table=[]
content_areas = []
'''------'''
styles = getSampleStyleSheet()
HeaderStyle = styles["Heading1"]
#get the Content Area Name
query = ((content_area_id == db.contentarea.id))
results = db(query).select(db.contentarea.name)
for row in results:
contentarea_name = row.name
#Create the name for the PDf being returned
pdfName = "Grade_"+str(grade)+"_"+contentarea_name+"_SR"+".pdf"
#set up the response headers so the browser knows to return a PDF document
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] ='attachment;filename=%s;'%pdfName
doc = SimpleDocTemplate(buff,pagesize=letter,rightMargin=72,leftMargin=72,topMargin=72,bottomMargin=18)
doc.title=pdfName
#Set up some styles
styles=getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
styles.add(ParagraphStyle(name='Indent', rightIndent=3))
styles.add(ParagraphStyle(name = 'Title2',
parent = styles['Normal'],
fontName = 'DejaVuSansCondensed',
fontSize = 18,
leading = 22,
spaceAfter = 6),
alias = 'title2')
#Time-Stamp
ptext = '<font size=12>%s</font>' % formatted_time
Story.append(Paragraph(ptext, styles["Normal"]))
Story.append(Spacer(1, 12))
Elements.extend(ptext)
#Administrator
ptext='<font size=12><b>Administrator</b></font>'
Story.append(Paragraph(ptext, styles["Justify"]))
Story.append(Spacer(1, 12))
Elements.extend(ptext)
#Grade Number and Content Area
ptext = '<font size=12><b>Grade %s %s Standards Report</b></font>'%(grade, contentarea_name)
Story.append(Paragraph(ptext, styles["Justify"]))
Story.append(Spacer(1, 7))
Elements.extend(ptext)
Story.append(Spacer(1,40))
#Graph Title
ptext = '<font size=15><b>Standards Progress</b></font>'
Story.append(Paragraph(ptext, styles["title"]))
i = 0
#get all the standards for a specific grade and content area
standard_query = standard_query = ((db.classes.grade_level == grade)&
(db.classes.id == db.student_classes.class_id)&
(db.student.id == db.student_classes.student_id)&
(db.student.id == db.student_grade.student_id)&
(db.grade.id == db.student_grade.grade_id)&
(db.grade.id == db.grade_standard.grade_id)&
(db.standard.id == db.grade_standard.standard_id)&
(db.classes.id == db.class_grade.class_id)&
(db.grade.id == db.class_grade.grade_id)&
(db.standard.content_area == db.contentarea.id)&
(db.contentarea.id == content_area_id))
standard_list = db(standard_query).select(db.standard.id, db.standard.short_name, db.standard.reference_number,db.student_grade.student_score, db.grade.score, db.contentarea.name)
standard_ref_list=[]
#Setup the Dictionary of standard averages
standard_dict = {}
for row in standard_list:
if row.standard.id in standard_dict.keys():
if((row.grade.score != 0.0) | (row.student_grade.student_score != 0.0)):
max_score = standard_dict[row.standard.id][0] + row.grade.score
student_score = standard_dict[row.standard.id][1] + row.student_grade.student_score
standard_dict[row.standard.id] = [max_score, student_score, row.standard.reference_number, row.standard.short_name]
else:
standard_dict[row.standard.id] = [row.grade.score, row.student_grade.student_score, row.standard.reference_number, row.standard.short_name]
standard_table = []
standard_averages=[[]]
#.........这里部分代码省略.........
示例15: range
# 需要导入模块: from reportlab.graphics.charts.legends import Legend [as 别名]
# 或者: from reportlab.graphics.charts.legends.Legend import y [as 别名]
lp.yValueAxis.labelTextFormat = lambda value: '%d MB' % (int(value) / 1000)
lp.yValueAxis.labels.fontName = 'Helvetica'
lp.yValueAxis.labels.fontSize = 7
lp.yValueAxis.visibleGrid = True
lp.yValueAxis.drawGridLast = True
lp.yValueAxis.valueMin = 0
if reserved:
if reserved[0]: lp.yValueAxis.valueMax = reserved[0]
if reserved[1]: lp.yValueAxis.valueStep = reserved[1]
for i in range(len(names)):
lp.lines[i].strokeColor = self.Color[i]
legend = Legend()
legend.x = 0
legend.y = h - 30
legend.boxAnchor = 'sw'
legend.colorNamePairs = [(self.Color[i], names[i]) for i in range(len(names))]
legend.fontName = 'Helvetica'
legend.fontSize = 8
legend.dxTextSpace = 5
legend.dy = 5
legend.dx = 5
legend.deltay = 5
legend.alignment ='right'
drawing.add(lp)
drawing.add(legend)
if title != None:
label = Label()