.pdf plots #680
robcarver17
started this conversation in
Ideas
.pdf plots
#680
Replies: 3 comments 1 reply
-
I've just committed a very basic account curve plot which works as described. The plot itself needs some stats adding to it I think to make it more interesting. I also need to include the option to email the report. Then I can circle back to the relevant issue that brought me to this point. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm happy with this and I've now got a new report to boot |
Beta Was this translation helpful? Give feedback.
0 replies
-
Have you considered generating HTML instead of PDF, or as a preliminary to
it?
One benefit of HTML is that you could include charts in the emailed
reports, and mixing text and images is of course not a problem. You could
always email a PDF file, but an email with images seems nicer.
Github.com can also display html files.
There are libraries available to convert HTML to PDF if you still want PDF
for some reason (although I know you don't like adding dependencies).
…On Tue, Jul 12, 2022 at 7:30 AM Robert Carver ***@***.***> wrote:
It would be nice to have the option to output reports into a .pdf file.
That way, figures can be plotted. The use case I'm thinking of is issue
#653 <#653> but
clearly one could use this for accounting p&l as well.
A quick check reveals that github.com can render .pdf so that is good.
The following code fragment seems the easiest way of generating .pdf files
consisting of multiple plots (from
https://datatofish.com/export-matplotlib-pdf/)
from matplotlib.backends.backend_pdf import PdfPages
Data1 = {'Unemployment_Rate': [6.1,5.8,5.7,5.7,5.8,5.6,5.5,5.3,5.2,5.2],
'Stock_Index_Price': [1500,1520,1525,1523,1515,1540,1545,1560,1555,1565]
}
df1 = DataFrame(Data1,columns=['Unemployment_Rate','Stock_Index_Price'])
with PdfPages(r'C:\Users\Ron\Desktop\Charts.pdf') as export_pdf:
plt.scatter(df1['Unemployment_Rate'], df1['Stock_Index_Price'], color='green')
plt.title('Unemployment Rate Vs Stock Index Price', fontsize=10)
plt.xlabel('Unemployment Rate', fontsize=8)
plt.ylabel('Stock Index Price', fontsize=8)
plt.grid(True)
export_pdf.savefig()
plt.close()
It also works on a headless terminal (checked).
It would be nice to include text as well, but let's park that for the
moment (can always be a seperate file).
Now, this does not fit well into the paradigm used by the reporting code
in psystemtrade. Remember, we generate a list of special objects (headers,
body_text, table) which is then 'parsed' into a single text string, which
we then email or dump to file etc.
MORE TBC
—
Reply to this email directly, view it on GitHub
<#680>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA3JWKVKH5NKN5EXDNF3XT3VTV6RPANCNFSM53LH7BPQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be nice to have the option to output reports into a .pdf file. That way, figures can be plotted. The use case I'm thinking of is issue #653 but clearly one could use this for accounting p&l as well.
A quick check reveals that github.com can render .pdf so that is good.
The following code fragment seems the easiest way of generating .pdf files consisting of multiple plots (from https://datatofish.com/export-matplotlib-pdf/)
It also works on a headless terminal (checked).
It would be nice to include text as well, but let's park that for the moment
Now, this does not fit well into the paradigm used by the reporting code in psystemtrade. Remember, we generate a list of special objects (headers, body_text, table) which is then 'parsed' into a single text string, which we then email or dump to file etc.
So a better way is to output each plot into a single .pdf file and then use PyPDF2 to merge them together.
We could include text by using https://github.com/baruchel/txt2pdf
We create a special object type plot_figure which holds the temp filename, the title of the plot and nothing else (that gives forward compatibility to when we can use a mixture of graphs and text).
Upon parsing, if the plot only consists of figures, these are merged into a single temp pdf file
If the plot has a mixture of text and figures then, for now, an error is thrown (in the future we could convert the text to pdf files and then merge those).
Beta Was this translation helpful? Give feedback.
All reactions