daft-dev / daft

Render probabilistic graphical models using matplotlib
https://docs.daft-pgm.org
MIT License
675 stars 118 forks source link

Plate labels and up having a blue background #98

Closed aryaz42 closed 6 years ago

aryaz42 commented 6 years ago

Plate labels end up having a blue background for me. For example when I run the classic.py file from the examples folder, I get this:

classic

davidwhogg commented 6 years ago

Strange? Do you have .matplotlibrc or other hidden commands?

dobos commented 6 years ago

The same issue here. I'm running daft from jupyter and my matplotlib version is 2.2.2 on windows. No customization, just installed a new env from conda-forge.

pgmtest

dobos commented 6 years ago

Interestingly, if I add the annotation manually, I don't see the blue background.

import daft
pgm = daft.PGM([4, 2])
pgm.add_node(daft.Node("Yi", r"$Y_I$", 1, 1))
pgm.add_node(daft.Node("a", r"$\mathbf{a}$", 2.8, 1))

pgm.add_edge("a", "Yi")

#pgm.add_plate(daft.Plate([0.1, 0.5, 1.9, 1],label=r'$N$'))
pgm.add_plate(daft.Plate([0.1, 0.5, 1.9, 1]))

pgm._ctx.ax().annotate("$i = 1,2,...,N$", [0.4,1.2])

pgm.render()

pgmtest

davidwhogg commented 6 years ago

that is a clue. Inside the code, do we use an annotate command?

dobos commented 6 years ago

Yes, on line 595:

https://github.com/dfm/daft/blob/e0d20534f5ce8ef6bb6bb79877500b4353fa357c/daft.py#L595

It can be the rest of the parameters, I haven't tested yet.

davidwhogg commented 6 years ago

can you try explicitly adding a facecolor=none and things like that in the annotate command? I think it takes the arguments listed here, but I am not sure!!

https://matplotlib.org/api/_as_gen/matplotlib.patches.PathPatch.html#matplotlib.patches.PathPatch

dobos commented 6 years ago

Actually, the bug is somewhere in the bbox parameter of annotate. If I pass dict({}) - daft default - I get the blue box, if I pass None it's fine. I'm thinking of a workaround. I was trying to pass bbox=None to the Plate constructor but that doesn't work because there's a dict(bbox) line in the initializer which fails with a None value.

davidwhogg commented 6 years ago

If you can find us a modification to that annotate() call in the code that protects this, let me know; we will push the change.

dobos commented 6 years ago

I've created a pull request.