pyplati / platipy

Processing Library and Analysis Toolkit for Medical Imaging in Python
https://pyplati.github.io/platipy/
Apache License 2.0
103 stars 24 forks source link

proportion problem #216

Closed jizhang02 closed 1 year ago

jizhang02 commented 1 year ago

Hello,

When I run the DVH example, the saved figure has an incongruous proportion. dvh_proportion

fig, df_metrics = visualise_dose(
    ct_image,
    dose,
    structures,
    dvh=dvh,
    d_points=[0, 95],
    v_points=[5],
    d_cc_points=[10],
    structure_for_limits=dose>5,
    expansion_for_limits=40,
    contour_cmap=plt.cm.get_cmap("rainbow"),
    dose_cmap=plt.cm.get_cmap("inferno"),
    title="TCGA_CV_5977 Dose Metrics")
figname = '/home/jing/python_code/DeepRT/00data-analysis/dvh.pdf'
plt.savefig(figname, dpi=150, orientation='landscape', format='pdf') # if need to save

I would like to know how to adjust the width of this color bar or the size of the whole figure. Thank you!

pchlap commented 1 year ago

Thanks for the bug report @jizhang02. Yeah these tables are a little tricky to position in matplotlib. For this particular visualisation we will run into problems either way when we want to visualise many structures (table rows) and many metrics (table columns).

One thing you could test is to see if reducing the dose metrics to plot fixes the rendering of the plot. E.g:

fig, df_metrics = visualise_dose(
    ct_image,
    dose,
    structures,
    dvh=dvh,
    d_points=[0, 95],
    v_points=[],
    d_cc_points=[],
    structure_for_limits=dose>5,
    expansion_for_limits=40,
    contour_cmap=plt.cm.get_cmap("rainbow"),
    dose_cmap=plt.cm.get_cmap("inferno"),
    title="TCGA_CV_5977 Dose Metrics")

To support plotting more structures/columns I will need to make the code in the visualise_dose function more robust, where the table is generated: https://github.com/pyplati/platipy/blob/c145f586169f6a08f7d3c7cb07b73e2e64e7dbd0/platipy/imaging/visualisation/dose.py#L204

Unfortunately I won't have time to look at this over the next month or two. But in case this is something you are working on resolving I'd be curious to hear what you find.

jizhang02 commented 1 year ago

hello,

This problem is solved by adding the code below:

fig, df_metrics = visualise_dose(
    ...)
figname = '/home/jing/python_code/DeepRT/00data-analysis/dvh.pdf'
plt.show() #  this sentence is necessary, otherwise the saved figure has proportion problem.
fig.savefig(figname, dpi=150, orientation='portrait', format='pdf', bbox_inches='tight', pad_inches=0.3) # if need to save