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

Plot hides left hand side with variable names and confidence intervals #38

Closed
LoveNordling opened this issue Dec 16, 2022 · 7 comments
Closed

Comments

@LoveNordling
Copy link

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

@LoveNordling
Copy link
Author

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
Copy link
Owner

LSYS commented Dec 25, 2022

@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"

@LoveNordling
Copy link
Author

@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
Copy link
Owner

LSYS commented Dec 28, 2022

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

@LoveNordling
Copy link
Author

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
Copy link
Owner

LSYS commented Dec 28, 2022

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")

@LoveNordling
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants