LSYS/forestplot

Plot hides left hand side with variable names and confidence intervals

LoveNordling opened this issue · 7 comments

When running the following code I get a plot without variable names and confidence intervals. I'm using running matplotlib 3.6.2, numpy 1.22.4 and pandas 1.5.1

`import csv
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import forestplot as fp

N = 10

ids = ["Number is: " + str(x) for x in range(N) ]

coef = np.random.uniform(0.4,2, size=N)
lower = coef - np.random.uniform(size=N)
upper = coef + np.random.uniform(size=N)

data = pd.DataFrame({"c":coef, "lower": lower, "upper": upper, "name": ids})
fig = fp.forestplot(data, estimate="c", ll="lower", hl="upper", varlabel="name")
plt.savefig("debug.png")`

debug

Same thing happens when I run the example

df = fp.load_data("sleep") # companion example data
df.head(3)

fp.forestplot(df, # the dataframe with results data
estimate="r", # col containing estimated effect size
ll="ll", hl="hl", # columns containing conf. int. lower and higher limits
varlabel="label", # column containing variable label
ylabel="Confidence interval", # y-label title
xlabel="Pearson correlation" # x-label title
)

LSYS commented

@LoveNordling Thanks for opening this issue. Seems related to #37.

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 Thank you for the reply! The version was 0.1.6. I have installed 0.1.3 now but it did not make a difference.

('matplotlib_inline' has no attribute 'version' but I used pip show matplotlib-inline to see the version)

LSYS commented

Strange, I can't reproduce it on matplotlib==3.6.2 and matplotlib-online==0.1.3. Did you restart the notebook/kernel after ?

I'm not using a notebook. Just python with a virtual environment on ubuntu 20. I'm using those versions for matplotlib and inline.

This is how I save the figure

fig = fp.forestplot(data, estimate="c", ll="lower", hl="upper", varlabel="name")
fig.figure.savefig("debug.png")

LSYS commented

I see, so matplotlib-inline is not (no longer) the issue then. I'm able to reproduce the issue now. I'll have to investigate more about why matplotlib looks different in script vs Jupyter notebook. If it helps, it probably should look right from a notebook.

Also, part of the issue was that the savefig line should probably be

plt.savefig("debug.png", bbox_inches="tight")

Using tight bbox_inches seems to have worked perfectly. Thank you very much for the help! Great and useful package!