Home > Software engineering >  Print python output to word doc or PDF?
Print python output to word doc or PDF?

Time:05-02

Does anyone have a simple way to print python output to a word doc? I want to capture the print statements and plot in a PDF (without showing any code). right now i am just copy and pasting, wondering if there is an easier way.

  • a-o are just random ints
group_a = (a,b,c,d,e)
group_b = (f,g,h,i,j)
group_c = (k,l,m,n,o)

width = 0.2

x = np.arange(5)

plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x, group_b, width, color = 'orange')
plt.bar(x 0.2, group_c, width, color = 'green')

plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")

plt.ylabel('%')

plt.legend(['Group A','Group B','Group C'])


print(f'Group A: {a},{b},{c},{d},{e}')
print(f'Group B: {f},{g},{h},{i},{j}')
print(f'Group C: {k},{l},{m},{n},{o}')

plt.show()

CodePudding user response:

Assuming you are using matplotlib.pyplot, you should be able to go with plt.savefig('line_plot.pdf')

CodePudding user response:

This works for me:

with open("randomfile.txt", "w") as external_file:
add_text = "This text will be added to the file"
print(add_text, file=external_file)
external_file.close()
  • Related