mauve
mauve

Reputation: 2763

How do I label units in a ReportLab Lineplot?

Can anyone tell me the attribute to set to label the units on a LinePlot in ReportLab? Also, if you know how to set a title, that would be ultimately super helpful.

drawing = Drawing(50,50)
data = [(tuple(zip(matfile['chan'].item([6],matfile['chan'].item()[7].item()[0])))]
lp = LinePlot()
lp.data = data
lp.????? = (str(matfile['chan'].item()[3]), str(matfile['chan'].item()[2]))
drawing.add(lp)
elements.append(drawing)

This is actually going to be inside a loop - I load a .mat file and there's about 50 channels, and I am going to plot almost all of them. Separately. But first I need to get a handle on assigning the labels (title text, which will be the same as the channel, then the units for the axes...) X Axis label should always be 'Seconds', Y axis label will vary... sometimes a %, sometimes a pressure or temperature or speed, etc.

Upvotes: 1

Views: 849

Answers (1)

mauve
mauve

Reputation: 2763

I have no idea how to do THAT, but I ended up using framing tables and I cobbled together something.I did not succeed in rotating the text for the y axis label.

for channel in channels:
    drawing = Drawing(0,0)
    data = [(tuple(zip(matfile[channel].item()[6],matfile[channel].item()[7].item()[0])))]
    lp = LinePlot()
    lp.data = data
    lp.width = 6*inch
    lp.height = 3.25*inch

    stylesheet = getSampleStyleSheet()
    y_label = Paragraph(str(matfile[channel].item()[2]), stylesheet['Normal'])

    drawing.add(lp)
    plot_table = [['',str(channel)],
                  [y_label, drawing],
                  ['',matfile[channel].item()[3]]]

    t_framing_table = Table(plot_table)
    t_framing_table._argH[1] = lp.height + .5*inch
    t_framing_table._argW[1] = lp.width


    elements.append(t_framing_table)
    if  break_page:
        elements.append(PageBreak())
        break_page = False
    else:
        break_page = True

Upvotes: 1

Related Questions