本文整理汇总了Python中reportlab.graphics.charts.barcharts.VerticalBarChart.width方法的典型用法代码示例。如果您正苦于以下问题:Python VerticalBarChart.width方法的具体用法?Python VerticalBarChart.width怎么用?Python VerticalBarChart.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.graphics.charts.barcharts.VerticalBarChart
的用法示例。
在下文中一共展示了VerticalBarChart.width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vertical_bar_chart_draw
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def vertical_bar_chart_draw(self, values, days, llabels):
d = Drawing(0, 170)
# chart
bc = VerticalBarChart()
# set width and height
bc.height = 125
bc.width = 470
# set data
bc.data = values
# set distance between bars elements
bc.barSpacing = 0.5
# set labels position under the x axe
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
# set name displayed for x axe
bc.categoryAxis.categoryNames = days
# set label format for each bar
bc.barLabelFormat = '%d'
# set distance between top of bar and it's label
bc.barLabels.nudge = 7
# set some charactestics for the Y axe
bc.valueAxis.labelTextFormat = '%d km/h'
bc.valueAxis.valueMin = 0
d.add(self.title_draw(250, 190, _('Wind speed statistics')))
d.add(bc)
d.add(self.legend_draw(llabels, bc, x=480, y=165, boxAnchor='ne',
columnMaximum=1, type='bar'))
# d.add(bcl)
return d
示例2: draw_bar_chart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def draw_bar_chart(pdf_text, page_height):
'''Currently generates a dummy graph.
Next, need to pass in data that shall
be the reactors temp throughout the
sequence.
'''
pdf_text.showPage()
drawing = Drawing(400, 200)
data = [
(13, 5, 20, 22, 37, 45, 19, 4),
(14, 6, 21, 23, 38, 46, 20, 5)
]
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 300
bc.data = data
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 50
bc.valueAxis.valueStep = 10
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 30
bc.categoryAxis.categoryNames = ['Jan-99','Feb-99','Mar-99','Apr-99','May-99','Jun-99','Jul-99','Aug-99']
drawing.add(bc)
renderPDF.draw(drawing, pdf_text, inch, inch)
return page_height
示例3: conversion_chart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def conversion_chart(data, labels):
"""Create chart that can be drawn as a gif with given data/labels"""
drawing = Drawing(500, 400)
bc = VerticalBarChart()
bc.x = 80
bc.y = 80
bc.height = 290
bc.width = 390
bc.data = data
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 100
bc.valueAxis.valueStep = 10
bc.valueAxis.labelTextFormat = '%2.2f'
bc.barLabels.fontSize = 15
bc.barLabelFormat = '%2.2f'
bc.barLabels.boxAnchor = 's'
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = 2
bc.categoryAxis.labels.angle = 30
bc.categoryAxis.categoryNames = labels
drawing.add(bc)
return drawing
示例4: print_chunks_chart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def print_chunks_chart(self):
nChunks = len(self.filechunks)
d = Drawing(400, 140)
traffic_MB = [n/(1024*1024) for n in self.traffic]
data = [traffic_MB]
bc = VerticalBarChart()
## bc.x = 0
## bc.y = 10
bc.height = 100
bc.width = 370
bc.data = data
bc.categoryAxis.tickUp = 0.5
bc.categoryAxis.tickDown = 1.5
bc.categoryAxis.categoryNames = []
for n in range(nChunks):
if n%5 == 0:
bc.categoryAxis.categoryNames.append( str(n) )
else:
bc.categoryAxis.categoryNames.append('')
bc.bars.strokeWidth = 0.3
bc.valueAxis.labels.fontSize = 6
bc.categoryAxis.labels.fontSize = 6
bc.bars[0].fillColor = colors.lightblue
bc.valueAxis.valueMin = 0
d.add(bc)
drawing = GraphicsDrawing(d, 'Traffic per chunk in MB')
self.story.append(drawing)
self.story.append(Spacer(0.01,1.0*cm))
示例5: recommend
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def recommend(self, howMany):
userKnownLanguages = {}
for button in self.buttons:
if(button.clicked == True):
if button.t not in userKnownLanguages:
userKnownLanguages[button.t] = 1
topicOfChoice = ""
# Grab the topic the user selected
try:
index = self.listbox.curselection()[0]
topicOfChoice = self.listbox.get(index)
except IndexError:
pass
nearestCluster = classifier.nearest(userKnownLanguages, self.indexByTopic)
for frame in self.frames:
frame.pack_forget()
self.displayRecommendations(topicOfChoice, userKnownLanguages)
data = classifier.difference(self.indexByTopic[nearestCluster]['languages'], userKnownLanguages)
labels,d1 =zip(*data)
d = Drawing(300,200)
chart = VerticalBarChart()
chart.width = 260
chart.height = 160
chart.x = 20
chart.y = 10
chart.data = [d1]
chart.categoryAxis.categoryNames = labels
d.add(chart)
d.save(formats=['pdf'],outDir='.',fnRoot='graph')
os.system('open graph.pdf')
示例6: sample1bar
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def sample1bar(data=[(13, 5, 20, 22, 37, 45, 19, 4)]):
drawing = Drawing(400, 200)
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 300
bc.data = data
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 60
bc.valueAxis.valueStep = 15
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 30
catNames = string.split('Jan Feb Mar Apr May Jun Jul Aug', ' ')
catNames = map(lambda n:n+'-99', catNames)
bc.categoryAxis.categoryNames = catNames
drawing.add(bc)
return drawing
示例7: createReadsHistogram
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [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)
示例8: generateversionchart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def generateversionchart((versionpickle, picklehash, imagedir, pickledir)):
datapickle = open(os.path.join(pickledir, versionpickle), 'rb')
data = cPickle.load(datapickle)
datapickle.close()
## calculate the possible widths and heights of chart, bars, labels and so on
maxversionstring = max(map(lambda x: len(x[0]), data))
barwidth = 15
chartwidth = len(data) * barwidth + 10 * len(data)
maxvalue = max(map(lambda x: x[1], data))
step = int(math.log(maxvalue,10))
valueStep = pow(10,step)
## calculate a possible good value for startx and starty so labels are not cut off
startx = max(10 + step * 10, 30)
## TODO: fiddle with values to create nicer looking graphs
starty = maxversionstring * 10 + 20
drawheight = 225 + starty
drawwidth = chartwidth + startx + 10
## create the drawing
drawing = Drawing(drawwidth, drawheight)
bc = VerticalBarChart()
bc.x = startx
bc.y = starty
bc.height = 200
bc.width = chartwidth
bc.data = [tuple(map(lambda x: x[1], data))]
bc.strokeColor = colors.white
bc.valueAxis.valueMin = 0
bc.valueAxis.labels.fontSize = 16
bc.valueAxis.valueMax = maxvalue
bc.valueAxis.valueStep = valueStep
bc.categoryAxis.labels.boxAnchor = 'w'
bc.categoryAxis.labels.dx = 0
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = -90
bc.categoryAxis.labels.fontSize = 16
bc.categoryAxis.categoryNames = map(lambda x: x[0], data)
bc.barWidth = barwidth
drawing.add(bc)
outname = os.path.join(imagedir, picklehash)
renderPM.drawToFile(drawing, outname, fmt='PNG')
return picklehash
示例9: getChart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def getChart(self):
d = Drawing(300, 200)
chart = VerticalBarChart()
chart.width = 560
chart.height = 460
chart.x = 50
chart.y = 50
chart.height = 125
chart.width = 300
chart.strokeColor = colors.black
chart.valueAxis.valueMin = 0
chart.valueAxis.valueMax = 100
chart.valueAxis.valueStep = 10
chart.categoryAxis.labels.boxAnchor = 'ne'
chart.categoryAxis.labels.dx = 8
chart.categoryAxis.labels.dy = -2
chart.categoryAxis.labels.angle = 0
chart.data = self.marks#self.averages
chart.categoryAxis.categoryNames = self.chartXValues#self.studentNumbers
d.add(chart)
#d.save(fnRoot='test', formats=['png', 'pdf'])
return d
示例10: run
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def run(self, include_sub_survey=False, dimensions=[]):
# Build data set
averages = []
category_names = []
for dimension in self.getDimensions():
averages.append(self.get_average_score_for_dimension(
include_sub_survey=include_sub_survey,
dimension=dimension))
category_names.append(dimension)
drawing = Drawing(600, 300)
bc = VerticalBarChart()
bc.x = 20
bc.y = 20
bc.height = 260
bc.width = 580
bc.data = [averages]
bc.categoryAxis.categoryNames = category_names
bc.categoryAxis.labels.fontName = 'Helvetica'
bc.categoryAxis.labels.fontSize = 10
bc.categoryAxis.labels.textAnchor = 'middle'
bc.categoryAxis.visibleTicks = 0
bc.valueAxis.valueMax = 100.0
bc.valueAxis.valueMin = min(averages, 0)
bc.valueAxis.labels.fontName = 'Helvetica'
bc.valueAxis.labels.fontSize = 10
bc.valueAxis.labels.textAnchor = 'middle'
bc.barLabelFormat = '%.0f'
bc.barLabels.dy = 8
bc.barLabels.fontName = 'Helvetica'
bc.barLabels.fontSize = 10
bc.barWidth = len(averages)
bc.fillColor = None
drawing.add(bc)
# Write out
data = drawing.asString('png')
request = self.REQUEST
response = request.RESPONSE
response.setHeader('Content-Type', 'image/png')
response.setHeader('Content-Disposition','inline; filename=%s.png' % self.getId())
response.setHeader('Content-Length', len(data))
response.setHeader('Cache-Control', 's-maxage=0')
return data
示例11: chartBins
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def chartBins(bins, filename):
data = []
labels = []
keys = bins.keys()
keys.sort()
for k in keys:
mid = (k[1] + k[0]) / 2.0
labels.append(str(mid))
data.append(len(bins[k]))
maxval = max(data)
data = [tuple(data)]
# now, make the chart
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 500
bc.width = 1100
bc.data = data
bc.valueAxis.valueMin = 0
bc.valueAxis.valueStep = 10
bc.valueAxis.valueMax = maxval + bc.valueAxis.valueStep
bc.categoryAxis.labels.boxAnchor = "n"
# bc.categoryAxis.labels.dx = 8
# bc.categoryAxis.labels.dy = -2
# bc.categoryAxis.labels.angle = 30
new_labels = []
for i, l in enumerate(labels):
if i % 5 == 0:
new_labels.append(l)
else:
new_labels.append("")
# bc.categoryAxis.categoryNames = labels
bc.categoryAxis.categoryNames = new_labels
drawing = Drawing(1200, 600)
drawing.add(bc)
from reportlab.graphics import renderPM
renderPM.drawToFile(drawing, output_filename)
示例12: graphout
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def graphout(statenames, data):
drawing = Drawing(500, 200)
lc = VerticalBarChart()
lc.x = 30
lc.y = 50
lc.height = 125
lc.width = 450
lc.data = data
statenames = statenames
lc.categoryAxis.categoryNames = statenames
lc.categoryAxis.labels.boxAnchor = 'n'
lc.categoryAxis.labels.angle = 270
lc.valueAxis.valueMin = 0
lc.valueAxis.valueMax = 10000000 #1500
lc.valueAxis.valueStep = 1000000 #300
drawing.add(lc)
return drawing
示例13: test_21_barCharts
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def test_21_barCharts(self):
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib import colors
from reportlab.platypus import SimpleDocTemplate, Spacer, Paragraph
from reportlab.pdfbase import pdfmetrics
from reportlab.graphics.shapes import Drawing
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.graphics.charts.barcharts import VerticalBarChart
pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
stylesheet = getSampleStyleSheet()
elements = []
doc = SimpleDocTemplate("demo.pdf")
elements.append(Paragraph('<font name="chsFont">JY.zenist.song - 俊毅</font>', stylesheet['Title']))
elements.append(Spacer(1,12))
d = Drawing(400,200)
data = [
(13,5,20,22,37,45,19,4),
(14,6,21,23,38,46,20,5)
]
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 300
bc.data = data
bc.strokeColor = colors.black
bc.groupSpacing = 10
bc.barSpacing = 2.5
bc.valueAxis._valueMin = 0
bc.valueAxis._valueMax = 50
bc.valueAxis._valueStep = 10
bc.categoryAxis.categoryNames = ['1','2','3','4','5','6','7','8']
# bc.categoryAxis.style = 'stacked'
d.add(bc)
elements.append(d)
doc.build(elements)
示例14: draw
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def draw(self, cur_drawing, start_x, start_y, end_x, end_y):
"""Draw a bar chart with the info in the specified range."""
bar_chart = VerticalBarChart()
if self.chart_title:
self._draw_title(cur_drawing, self.chart_title,
start_x, start_y, end_x, end_y)
# set the position of the bar chart
x_start, x_end, y_start, y_end = self._determine_position(start_x,
start_y,
end_x,
end_y)
bar_chart.x = x_start
bar_chart.y = y_start
bar_chart.width = abs(x_start - x_end)
bar_chart.height = abs(y_start - y_end)
# set the information in the bar chart
bar_chart.data = self.display_info
bar_chart.valueAxis.valueMin = min(self.display_info[0])
bar_chart.valueAxis.valueMax = max(self.display_info[0])
for data_set in self.display_info[1:]:
if min(data_set) < bar_chart.valueAxis.valueMin:
bar_chart.valueAxis.valueMin = min(data_set)
if max(data_set) > bar_chart.valueAxis.valueMax:
bar_chart.valueAxis.valueMax = max(data_set)
# set other formatting options
if len(self.display_info) == 1:
bar_chart.groupSpacing = 0
style = TypedPropertyCollection(BarChartProperties)
style.strokeWidth = 0
style.strokeColor = colors.green
style[0].fillColor = colors.green
bar_chart.bars = style
# set the labels
# XXX labels don't work yet
# bar_chart.valueAxis.title = self.x_axis_title
# bar_chart.categoryAxis.title = self.y_axis_title
cur_drawing.add(bar_chart)
示例15: create_barchart
# 需要导入模块: from reportlab.graphics.charts.barcharts import VerticalBarChart [as 别名]
# 或者: from reportlab.graphics.charts.barcharts.VerticalBarChart import width [as 别名]
def create_barchart(barchart_data):
color=[green,red,blue,yellow,black]
data_length=len(barchart_data["data"])
bar_chart = Drawing(400, 200)
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 300
bc.data = barchart_data["data"]
bc.fillColor=lightblue
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 50
bc.valueAxis.valueStep = 10
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 30
bc.categoryAxis.categoryNames = list(barchart_data["label"][0])
for i in xrange(data_length):
bc.bars[i].fillColor = color[i]
bar_chart.add(bc)
###legend####
bar_leg = LineLegend()
bar_leg.boxAnchor = 'sw'
bar_leg.x = 100
bar_leg.y = -1
bar_leg.columnMaximum = 1
bar_leg.yGap = 0
bar_leg.deltax = 50
bar_leg.deltay = 0
bar_leg.dx = 10
bar_leg.dy = 1.5
bar_leg.fontSize = 10
bar_leg.alignment = 'right'
bar_leg.dxTextSpace = 5
bar_leg.colorNamePairs = [(color[i],barchart_data["legend"][0][i]) for i in xrange(data_length)]
bar_chart.add(bar_leg)
return bar_chart