Excess Whitespace Error in Jupyter
sjiang40 opened this issue · 7 comments
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.
Hi there @sjiang40, thank you for opening this issue.
Can you try a couple of things?
- Do a
pip install --upgrade forestplot
to make sure you are using the most recent v0.2.0. - Check what version of
matplotlib
you are using:import matplotlib matplotlib.__version
- I ran
pip install --upgrade forestplot
and confirmed that it's on v0.2.0 - My
matplotlib
version is 3.5.3
Rerunning the code with these 2 confirmed versions, I still get the same error
@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
@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.
@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"
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive.