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

Excess Whitespace Error in Jupyter #37

Closed
sjiang40 opened this issue Dec 2, 2022 · 7 comments
Closed

Excess Whitespace Error in Jupyter #37

sjiang40 opened this issue Dec 2, 2022 · 7 comments
Labels
Close in 30 days Will close in 30 days if inactive stale

Comments

@sjiang40
Copy link

sjiang40 commented Dec 2, 2022

I followed the install and quick start instructions in the README, but I'm having an issue with excess whitespace being added between the variable labels and the plot. Below are screenshots of the example as well as example with customization 5. The whitespace is added regardless of the width of the overall forest plot.

I am using Jupyter version 6.5.2 and Python 3.9.15 via Anaconda.

image

image

@LSYS
Copy link
Owner

LSYS commented Dec 5, 2022

Hi there @sjiang40, thank you for opening this issue.

Can you try a couple of things?

  1. Do a pip install --upgrade forestplot to make sure you are using the most recent v0.2.0.
  2. Check what version of matplotlib you are using:
    import matplotlib
    matplotlib.__version

@sjiang40
Copy link
Author

sjiang40 commented Dec 5, 2022

  1. I ran pip install --upgrade forestplot and confirmed that it's on v0.2.0
  2. My matplotlib version is 3.5.3

Rerunning the code with these 2 confirmed versions, I still get the same error

@sjiang40
Copy link
Author

@LSYS I managed to piece together a temporary fix for my issue by manually moving the y tick labels and table lines. Here's the code for my temporary fix; perhaps that can help with finding the issue.

ax = fp.forestplot(
    df,  # the dataframe with results data
    estimate="r",  # col containing estimated effect size 
    ll="ll", hl="hl",  # lower & higher limits of conf. int.
    varlabel="label",  # column containing the varlabels to be printed on far left
    capitalize="capitalize",  # Capitalize labels
    pval="p-val",  # column containing p-values to be formatted
    annote=["n", "power", "est_ci"],  # columns to report on left of plot
    annoteheaders=["N", "Power", "Est. (95% Conf. Int.)"],  # ^corresponding headers
    rightannote=["formatted_pval", "group"],  # columns to report on right of plot 
    right_annoteheaders=["P-value", "Variable group"],  # ^corresponding headers
    groupvar="group",  # column containing group labels
    group_order=["labor factors", "occupation", "age", "health factors", 
               "family factors", "area of residence", "other factors"],                   
    xlabel="Pearson correlation coefficient",  # x-label title
    xticks=[-.4,-.2,0, .2],  # x-ticks to be printed
    sort=True,  # sort estimates in ascending order
    table=True,  # Format as a table
    # Additional kwargs for customizations
    **{
         "marker": "D",  # set maker symbol as diamond
         "markersize": 30,  # adjust marker size
         "xlinestyle": (0, (10, 5)),  # long dash for x-reference line 
         "xlinecolor": "#808080",  # gray color for x-reference line
         "xtick_size": 12,  # adjust x-ticker fontsize
    }  
)

ax.tick_params(axis='y', pad=490)

lines = ax.get_lines()
for line in lines[1:3]:
    line.set_xdata([-1.73, -.43])

plt.show()

The above code generates the following image

image

@LSYS
Copy link
Owner

LSYS commented Dec 15, 2022

@sjiang40 One possible (short-term) solution is to freeze matplotlib to an older version. E.g.,

pip install matplotlib==3.4.3

and see if that works (best to do it in an env). Let me know if it works for you.

Regarding your follow-up message, it's not ideal to hardcode the limits but they may point to a more general solution (thanks for this!).
I should be able to find time to work on this properly around the end of the year.

@LSYS
Copy link
Owner

LSYS commented Dec 25, 2022

@sjiang40 After more investigation, the problem is likely with matplotlib-inline.

I can reproduce the wrong figures with matplotlib-inline>=0.1.4 but not with matplotlib-inline<=0.1.3.

Can you confirm that you are using matplotlib-inline>=0.1.4?

import matplotlib_inline
matplotlib_inline.__version__

If so, the solution is likely to freeze matplotlib-inline to 0.1.3 and below:

pip install "matplotlib-inline<=0.1.3"

@LSYS LSYS added Next Release To work on for new version release Close in 30 days Will close in 30 days if inactive and removed Type: Investigate labels Jan 2, 2023
@LSYS LSYS removed the Next Release To work on for new version release label Jan 2, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Feb 1, 2023
@github-actions
Copy link

github-actions bot commented Feb 3, 2023

This issue was closed because it has been inactive.

@github-actions github-actions bot closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Close in 30 days Will close in 30 days if inactive stale
Projects
None yet
Development

No branches or pull requests

2 participants