facebookresearch / balance

The balance python package offers a simple workflow and methods for dealing with biased data samples when looking to infer from them to some target population of interest.
https://import-balance.org
GNU General Public License v2.0
686 stars 41 forks source link

When using the RStudio IDE to run Python: Seaborn plots not working #29

Open tomwagstaff-opml opened 1 year ago

tomwagstaff-opml commented 1 year ago

Hi guys,

As reported before, the Seaborn-based plots don't seem to be working in a Python 3.10 environment on my Windows machine e.g. this line from the quick start: adjusted.covars().plot(library = "seaborn", dist_type = "kde"). It doesn't throw an error, just doesn't output any plots.

Here is my session info as requested by @talgalili - hope it helps!

-----
balance             0.3.0
pandas              1.4.3
session_info        1.0.0
-----
IPython             8.9.0
PIL                 9.4.0
asttokens           NA
backcall            0.2.0
beta_ufunc          NA
binom_ufunc         NA
coxnet              NA
cvcompute           NA
cvelnet             NA
cvfishnet           NA
cvglmnet            NA
cvglmnetCoef        NA
cvglmnetPredict     NA
cvlognet            NA
cvmrelnet           NA
cvmultnet           NA
cycler              0.10.0
cython_runtime      NA
dateutil            2.8.2
decorator           5.1.1
elnet               NA
executing           1.2.0
fishnet             NA
glmnet              NA
glmnetCoef          NA
glmnetControl       NA
glmnetPredict       NA
glmnetSet           NA
glmnet_python       NA
hypergeom_ufunc     NA
jedi                0.18.2
joblib              1.2.0
kiwisolver          1.4.4
loadGlmLib          NA
lognet              NA
matplotlib          3.6.3
mpl_toolkits        NA
mrelnet             NA
nbinom_ufunc        NA
nt                  NA
numpy               1.24.1
packaging           23.0
parso               0.8.3
patsy               0.5.3
pickleshare         0.7.5
pkg_resources       NA
plotly              5.13.0
prompt_toolkit      3.0.36
pure_eval           0.2.2
pygments            2.14.0
pyparsing           3.0.9
pytz                2022.7.1
rpycall             NA
rpytools            NA
scipy               1.8.1
seaborn             0.11.1
setuptools          65.6.3
six                 1.16.0
sklearn             1.2.1
stack_data          0.6.2
statsmodels         0.13.5
tenacity            NA
threadpoolctl       3.1.0
traitlets           5.9.0
wcwidth             0.2.6
wtmean              NA
-----
Python 3.10.9 | packaged by conda-forge | (main, Jan 11 2023, 15:15:40) [MSC v.1916 64 bit (AMD64)]
talgalili commented 1 year ago

Thanks for the report @tomwagstaff-opml

This is very odd, since I see that your python is 3.10.9, IPython 8.9.0, and seaborn 0.11.1, which is similar to what's used by gh actions (python is 3.10.6, IPython 8.9.0, and seaborn 0.11.1): https://import-balance.org/docs/tutorials/quickstart/

So it's not clear to me why this happens for you.

@stevemandala are you able to reproduce the issue with the seaborn plots on your machine?

stevemandala commented 1 year ago

I gave the tutorial a run in my Windows-based jupyter instance, but I wasn't able to repro the plotting issue from jupyter; plots seemed to output as expected.

Curious if this is an issue on the balance side or with the Seaborn plotting itself. @tomwagstaff-opml Do sample Seaborn plots like the one below work for you?

import seaborn as sns
penguins = sns.load_dataset("penguins")
sns.histplot(data=penguins, x="flipper_length_mm", hue="species", multiple="stack")
tomwagstaff-opml commented 1 year ago

Hi @stevemandala,

Sorry for the delay in replying, I'm afraid I ran out of time to devote to this. The issue here might be that I'm using the RStudio IDE to run Python. When I ran your code I just got the description of the object on the console: <AxesSubplot: xlabel='flipper_length_mm', ylabel='Count'>

However, when I added these 2 lines:

import matplotlib.pyplot as plt
plt.show()

Then your example appeared in my plot pane.

talgalili commented 1 year ago

Thanks Tom, that sounds like a good solution. Did you place your lines before the plot() commands or after them?

On Fri, 10 Feb 2023, 20:08 Tom Wagstaff, @.***> wrote:

Hi @stevemandala https://github.com/stevemandala,

Sorry for the delay in replying, I'm afraid I ran out of time to devote to this. The issue here might be that I'm using the RStudio IDE to run Python. When I ran your code I just got the description of the object on the console: <AxesSubplot: xlabel='flipper_length_mm', ylabel='Count'>

However, when I added these 2 lines:

import matplotlib.pyplot as plt plt.show()

Then your example appeared in my plot pane.

— Reply to this email directly, view it on GitHub https://github.com/facebookresearch/balance/issues/29#issuecomment-1426161871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBUWD6GVIHQ2U6JHDCTWWZ7YZANCNFSM6AAAAAAUMQKQ3E . You are receiving this because you were mentioned.Message ID: @.***>

tomwagstaff-opml commented 1 year ago

Ahh - good question - I added my lines afterwards - but this only worked with Steve's example, didn't try it with the balance package commands

talgalili commented 1 year ago

@tomwagstaff-opml thanks for the report! I've updated this issue to be "When using the RStudio IDE to run Python: Seaborn plots not working".

If you get around to it, could you please try using a jupyter notebook to run the example, and see if it works fine for you there? Even if not - it's fine - I think you've given us enough input to better understand this.

To be honest - I doubt that we'll prioratize supporting RStudio's IDE in the near future. But if you or someone else would like to try and do a PR, we'd be happy to review it (and if it works, to include it back into balance)

Thanks again Tom!