Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Reportlab: Add xlabel, ylabel and grid to lineplot
#1
Good morning, I'm Denis and I gently ask help about reporlab library. I'm trying to create a pdf with some graphs automatically with python, in particular with the plotline function of reportlab, but I have some problems to add Xlabel and Ylabel, or better what the two axis represent, and the grid and legend.
Can someone could help me to solve this difficulty?

Here a part of the code which I implemented:



import reportlab

from reportlab.pdfgen import canvas
from reportlab.graphics import renderPDF
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin
from reportlab.graphics.charts.lineplots import LinePlot
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.widgets.markers import makeMarker
from reportlab.graphics.charts.legends import LineLegend
from reportlab.graphics.samples.excelcolors import *
from reportlab.lib.validators import *
from reportlab.lib.colors import Color
from reportlab.graphics.charts.utils import *
from reportlab.graphics.charts.lineplots import GridLinePlot
from reportlab.graphics.charts.axes import XValueAxis, YValueAxis, AdjYValueAxis, NormalDateXValueAxis
from reportlab.graphics.charts.lineplots import GridLinePlot
from reportlab.lib.validators import Auto
from reportlab.graphics.charts.axes import NormalDateXValueAxis

...
def line_plot():
drawing = Drawing(500, 800)
lp1 = LinePlot()
lp1.x = 200
lp1.y = 550
lp1.height = 200
lp1.width = 200
lp1.data = Data
lp1.joinedLines = 1
lp1.lines[0].symbol = makeMarker('FilledCircle')
lp1.lines[1].symbol = makeMarker('Circle')
Data = [[[1,1], [2,2], [2.5,1], [3,3], [4,5]],[[1,2], [4,6]]]
lp1.xValueAxis.labelTextFormat = '%2.1f'
drawing.add(lp)
return drawing

the_canvas = canvas.Canvas("output.pdf")
the_canvas.drawString(100,750,"Welcome to Reportlab!")
renderPDF.draw(line_plot(), the_canvas, 10, 10)
the_canvas.showPage()
the_canvas.save()



Thank you really much
Denis
Quote
#2
Please re-post using code tags, see BBCODE
also when posting code, use shift-ctrl-v which will preserve indentation
Quote
#3
I'm sorry

import reportlab
from reportlab.pdfgen import canvas
from reportlab.graphics import renderPDF
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.lineplots import LinePlot
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.graphics.widgets.markers import makeMarker
from reportlab.graphics.charts.legends import LineLegend
from reportlab.graphics.charts.lineplots import GridLinePlot
from reportlab.graphics.charts.lineplots import GridLinePlot
from reportlab.lib.colors import Color
from reportlab.graphics.charts.legends import LineLegend
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin
from reportlab.lib.validators import Auto
from reportlab.graphics.charts.axes import NormalDateXValueAxis



def line_plot():
	drawing = Drawing(400, 200)
	Data = [[[1,1], [2,2], [2.5,1], [3,3], [4,5]],[[1,2], [4,6]]]
	lp = LinePlot()
	lp.y                             = 40
	lp.x                             = 30 
	lp.width                         = 500
	lp.height                        = 500


	lp.lineLabels.fontSize           = 6
	lp.lineLabels.boxStrokeWidth     = 0.5
	lp.lineLabels.visible            = 1
	lp.lineLabels.boxAnchor          = 'c'
	lp.lineLabels.angle              = 0
	lp.lineLabelNudge                = 10
	lp.joinedLines                   = 1
	lp.lines.strokeWidth             = 1.5

	lp.data  = Data
	drawing.add(lp)
	
	
	return drawing

the_canvas = canvas.Canvas("output.pdf")
the_canvas.drawString(100,750,"Welcome to Reportlab!")
renderPDF.draw(line_plot(), the_canvas, 10, 10)
the_canvas.showPage()

the_canvas.save()
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Inserting a variable name into xlabel myersluke 0 194 Jun-19-2019, 10:22 PM
Last Post: myersluke
  cyrillic symbols in tables in reportlab. hiroz 4 934 Mar-20-2019, 07:42 PM
Last Post: nilamo
  Python Reportlab Wordwrap Table Mady 0 1,218 Dec-18-2018, 06:31 AM
Last Post: Mady
  Reportlab Dynamic Table Q Gutt 0 1,567 Jun-13-2018, 10:18 PM
Last Post: Gutt
  ReportLab ek5442 2 1,520 Aug-24-2017, 01:29 PM
Last Post: ek5442
  Python ReportLab ek5442 6 3,325 Mar-15-2017, 07:47 PM
Last Post: ek5442

Forum Jump:


Users browsing this thread: 1 Guest(s)