Closed smarianimore closed 1 month ago
Good idea. I like to separate the visible
and the show
of plots.
I created a new version that should solve this issue! Update to the latest version.
pip install -U bnlearn
import bnlearn as bn
import matplotlib.pyplot as plt
df = bn.import_example('sprinkler')
model = bn.structure_learning.fit(df)
# Figure is visible and created
fig = bn.plot(model, params_static={'visible': True, 'showplot': True})
# Figure is visible but not created
fig = bn.plot(model, params_static={'visible': True, 'showplot': False})
plt.show()
# Figure is not visible but but created
fig = bn.plot(model, params_static={'visible': False, 'showplot': True})
# Figure is not visible but but created
fig = bn.plot(model, params_static={'visible': False, 'showplot': False})
plt.show()
Should be solved now with the last update! Reopen if not.
Dear @erdogant , many thanks!
I tried with {'visible': True, 'showplot': False}
and it works as intended (figure created with plot but not shown)
Perhaps the comments on the other modes have some typos as they do not make much sense to me, but my use case has been solved XD
Thanks!
I will look at the typos. I agree, some modes are likely edge cases but at least its complete now.
Dear devs, I found no way to avoid showing plots of learnt network, as setting parameter "visible"=False applies at two levels:
The "offending" code is in this line IMHO: https://github.com/erdogant/bnlearn/blob/b395e1688d521c4863aabd77c20c14fd96580242/bnlearn/bnlearn.py#L1177
The use case is to simply create a plot to be saved on file, without showing it.
Imho, bnlearn should not force plots to be shown, but only create them, return them, and let the user decide.
Another solution would be to introduce a 2nd parameter "show" to control the behaviour of the offending line instead of "visible".
What do you think?