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

Add coloured edge #66

Closed
donnachakirk opened this issue Mar 3, 2014 · 3 comments
Closed

Add coloured edge #66

donnachakirk opened this issue Mar 3, 2014 · 3 comments

Comments

@donnachakirk
Copy link

Hi,
I really like daft & have begun to play around with it. I'm just trying to do something really simple explaining the inputs needed to model an NFW halo.

I've got a (probably really simple) question, I'd like to colour some of my lines but I'm not quite sure to how to do this with pgm.add_edge?
daft.Edge doesn't seem to nest like pgm.add_node(daft.Node())?
i.e. I get errors if I try pgn.add_edge(daft.Edge())

flowchart

@davidwhogg
Copy link
Collaborator

This is related to #87

@dsfulf
Copy link
Member

dsfulf commented Jan 6, 2019

This is fixed by #106.

Using this example:

from matplotlib import rc
rc("font", family="serif", size=12)
rc("text", usetex=True)

import daft

# Colors.
p_color = {"ec": "#46a546"}
s_color = {"ec": "#f89406"}

pgm = daft.PGM([3.6, 3.5], origin=[0.7, 0])

n = daft.Node("phi", r"$\phi$", 1, 3, plot_params=s_color)
n.va = "baseline"
pgm.add_node(n)
pgm.add_node(daft.Node("speckle_coeff", r"$z_i$", 2, 3, plot_params=s_color))
pgm.add_node(daft.Node("speckle_img", r"$x_i$", 2, 2, plot_params=s_color))

pgm.add_node(daft.Node("spec", r"$s$", 4, 3, plot_params=p_color))
pgm.add_node(daft.Node("shape", r"$g$", 4, 2, plot_params=p_color))
pgm.add_node(daft.Node("planet_pos", r"$\mu_i$", 3, 3, plot_params=p_color))
pgm.add_node(daft.Node("planet_img", r"$p_i$", 3, 2, plot_params=p_color))

pgm.add_node(daft.Node("pixels", r"$y_i ^j$", 2.5, 1, observed=True))

# Edges.
p_color.update({"fc": "#46a546"})
s_color.update({"fc": "#f89406"})
pgm.add_edge("phi", "speckle_coeff", plot_params=s_color)
pgm.add_edge("speckle_coeff", "speckle_img", plot_params=s_color)
pgm.add_edge("speckle_img", "pixels")

pgm.add_edge("spec", "planet_img", plot_params=p_color)
pgm.add_edge("shape", "planet_img", plot_params=p_color)
pgm.add_edge("planet_pos", "planet_img", plot_params=p_color)
pgm.add_edge("planet_img", "pixels")

# And a plate.
pgm.add_plate(daft.Plate([1.5, 0.2, 2, 3.2], label=r"exposure $i$",
shift=-0.1))
pgm.add_plate(daft.Plate([2, 0.5, 1, 1], label=r"pixel $j$",
shift=-0.1))

# Render and save.
pgm.render()
pgm.figure.savefig("exoplanets.pdf")
pgm.figure.savefig("exoplanets.png", dpi=150)

exoplanets

@davidwhogg
Copy link
Collaborator

I'm closing this; reopen if you still have issues

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

3 participants