erdogant / distfit

distfit is a python library for probability density fitting.
https://erdogant.github.io/distfit
Other
367 stars 26 forks source link

New User Plot Question #26

Closed francoisdejgr closed 6 months ago

francoisdejgr commented 1 year ago

Greetings

I am a new user read about it here "https://towardsdatascience.com/how-to-find-the-best-theoretical-distribution-for-your-data-a26e5673b4bd"

I am also reading the information here "https://erdogant.github.io/distfit/pages/html/index.html"

The code runs, but no PDF is being generated and I get an odd message (don't know if it is related) : [colourmap]> Warning: Colormap [Set1] can not create [11] unique colors! Available unique colors: [9]

Question: Is there any special settings for creating the PDF? How can I set the output location of the PDF?

This is the sample I ran

from distfit import distfit
import numpy as np

# Example data
X = np.random.normal(10, 3, 2000)
y = [3, 4, 5, 6, 10, 11, 12, 18, 20]

# From the distfit library import the class distfit
from distfit import distfit

# Initialize
dfit = distfit(todf=True)

# Search for best theoretical fit on your empirical data
results = dfit.fit_transform(X)
dfit.plot()

Regards

DiTo97 commented 1 year ago

Hi @francoisdejgr,

I have just tested your snippet of code and the PDF plotting works fine for me (on Colab)

As for the warning, it is just a Matplotlib warning that you are trying to draw a plot with 11 curves (the 11 theoretical distributions that have been fitted to the data) with a colour set with only 9 available unique colours. You must choose a different colour set that has a sufficient number of unique colours, i.e. 11 or more.

Regardless, wait for the author's response.

erdogant commented 1 year ago

True @DiTo97. Should I disable the warning for the colors by default? I can understand it can be annoying or confusing. Regarding the plot, I am not sure why it does not show up. Maybe it has something to do with the way you have configured your matplotlib(?) Did you try %matplotlib inline or %matplotlib qt ?

francoisdejgr commented 1 year ago

Greetings

Thx for your reply. I did not make any changes to mathplotlib. I am using Windows. Will check your suggestion and let you know

Regards

On Mon, 06 Feb 2023, 20:41 Erdogan Taskesen, @.***> wrote:

True. Should I disable the warning for the colors by default? I can understand it can be annoying or confusing. Regarding the plot, I am not sure why it does not show up. Maybe it has something to do with the way you have configured your matplotlib(?) Did you try %matplotlib inline or %matplotlib qt ?

— Reply to this email directly, view it on GitHub https://github.com/erdogant/distfit/issues/26#issuecomment-1419571068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEISDX2HGQ7A57U43JLJ3KDWWFAVNANCNFSM6AAAAAAUSMSWWI . You are receiving this because you were mentioned.Message ID: @.***>

krzywicki1 commented 1 year ago

Hey I had same problem! Importing matplotlib

import matplotlib.pyplot as plt

and adding

plt.show()

at the end of code worked for me!

erdogant commented 1 year ago

True. plt.show() is required for some IDEs/machines/environments. But the existing functions do not actively plot (with plt.show()) because axes can be given as input. Otherwise, it is not possible to update figures.

fig, ax = plt.subplots(1,2, figsize=(25, 10))
dfit.plot(chart='PDF', ax=ax[0])
dfit.plot(chart='CDF', ax=ax[1])

# Try:
plt.show

# Or the figure:
fig
erdogant commented 6 months ago

This issue seems to be solved. Otherwise, please re-open.

rubensmatosjr commented 5 months ago

Hey I had same problem! Importing matplotlib

import matplotlib.pyplot as plt

and adding

plt.show()

at the end of code worked for me!

I had a similar issue, but your solution works for me. Thanks.