Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top of the plot gets cut off #47

Closed
sayadennis opened this issue Jan 16, 2023 · 3 comments
Closed

Top of the plot gets cut off #47

sayadennis opened this issue Jan 16, 2023 · 3 comments

Comments

@sayadennis
Copy link

sayadennis commented Jan 16, 2023

Hello! Thank you for building this awesome package.

I'm trying to visualize some odds-ratios and their confidence intervals, and I'm running into an issue where the top of the plot seems to get cut off.

I installed forestplot today via conda with conda install -c conda-forge forestplot, and am running it on Python 3.9.6.

Data

>>> df
  varname        or       low      high
0       a  1.761471  0.926563  3.022285
1       b  1.443660  0.517059  3.130794
2       c  1.525227  0.603459  3.082003
3       d  0.895682  0.463703  1.660016
4       e  4.025670  1.196941  8.932753
5       f  1.086105  0.555171  2.045735

Plotting code

fp.forestplot(df,  # the dataframe with results data
    estimate='or',  # col containing estimated effect size 
    ll='low', hl='high',  # columns containing conf. int. lower and higher limits
    varlabel='varname',  # column containing variable label
    ylabel='Confidence interval',  # y-label title
    xlabel='Odds Ratio',  # x-label title
    color_alt_rows=True,
    figsize=(4,8),
    **{
        'xline' : 1.,
        "xlinestyle": (0, (10, 5)),  # long dash for x-reference line 
    }
)

plt.savefig('test_forest_plot.png', bbox_inches='tight')

What I'm seeing is the attached image, where the top of the plot (where variable "a" should be) is getting cut off. I've tried adjusting the plot size but the issue persists. Any insight or advice would be appreciated!

20230116_test_forest_plot

@Chloe-Hao
Copy link

Hi, I also had the same problem. Have you gotten the answer on how to solve it

@LSYS
Copy link
Owner

LSYS commented Jan 19, 2023

Hi @sayadennis, thank you for raising this issue.

A quick solution is to adjust the ylim using ax.set_ylim(0, 5.5) (@Chloe-Hao adjust 5.5 accordingly based on how many rows you have):

ax = fp.forestplot(df,  # the dataframe with results data
    estimate='or',  # col containing estimated effect size 
    ll='low', hl='high',  # columns containing conf. int. lower and higher limits
    varlabel='varname',  # column containing variable label
    ylabel='Confidence interval',  # y-label title
    xlabel='Odds Ratio',  # x-label title
    color_alt_rows=True,
    figsize=(4,8),
    **{
        'xline' : 1.,
        "xlinestyle": (0, (10, 5)),  # long dash for x-reference line 
    }
)
ax.set_ylim(0, 5.5)
plt.savefig('test_forest_plot.png', bbox_inches='tight')

image

This seems to be a non-issue in v0.2.0. I'll fix this in the next patch.

@sayadennis
Copy link
Author

@LSYS This solves the issue, thanks! I appreciate the prompt response.

This was referenced Feb 8, 2023
@LSYS LSYS mentioned this issue Feb 10, 2023
LSYS added a commit that referenced this issue Feb 10, 2023
* Fix spacing issue at top of plot (fixes #48, #47)
* Create notebook for some simple regression tests (closes #49)
* Tidy imports using isort (closes #50)
* Allowed thresholds and symbols for p-values to be passedthrough (fixes #51)
* Fix different heigh and fontsize for confidence interval and p-value labels (fixes #53)
* Update docs for RTD (closes #54) 
* Freeze matplotlib-inline dependency in setup.py (closes #56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants