【问题标题】:saving matplotlib bar plot into pdf using reportlabsaving matplotlib bar plot into pdf using reportlab
【发布时间】:2022-12-02 09:31:41
【问题描述】:

so i am trying to use the below code to save a matplotlib generated plot into a pdf file using reportlab

import matplotlib.pyplot as plt
from io import BytesIO
from reportlab.pdfgen import canvas
from reportlab.graphics import renderPDF
from svglib.svglib import svg2rlg
...
objects = [str(col[1]) for col in data3.columns][1:]
y_pos = np.arange(len(objects))
performance = data[5][1:]
fig = plt.figure()
plt.bar(y_pos, performance, align='center', alpha=0.5, color=['blue', 'blue',     'blue', 'yellow','yellow'], edgecolor='blue')
plt.xticks(y_pos, objects)
plt.ylabel('USD $Billions')
plt.title('Revenue')
fig = plt.figure()
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0)  # rewind the data
drawing = svg2rlg(imgdata)

renderPDF.draw(drawing, pdf, 10, 40)
pdf.save()

but i get the following error:

Traceback (most recent call last):
  File "./main.py", line 94, in <module>
    renderPDF.draw(drawing, pdf, 10, 40)
  File "/usr/lib/python3/dist-packages/reportlab/graphics/renderPDF.py", line 29, in draw
    R.draw(renderScaledDrawing(drawing), canvas, x, y, showBoundary=showBoundary)
  File "/usr/lib/python3/dist-packages/reportlab/graphics/renderbase.py", line 172, in renderScaledDrawing
    renderScale = d.renderScale
AttributeError: 'NoneType' object has no attribute 'renderScale'

【问题讨论】:

    标签: python matplotlib reportlab


    【解决方案1】:

    Were you able to figure this out?

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 2022-12-02
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2022-11-20
      • 1970-01-01
      相关资源
      最近更新 更多