I am producing a simple, Python-based program that produces graphviz graphs as output. I would like to use custom nodes that depict data from the program. Using custom nodes is simple enough once you have the image, but I am having trouble figuring out a convenient method of producing the images I want.
Specifically, I would like the nodes to be circles whose area represents a measured value but with a gradient that represents the uncertainty in that value. It seems reasonable to use a contour map produced with some math program (e.g. sagemath) but these tend to make square images that are not scaled. Alternatively, the gradient functions on image manipulation programs seem difficult to relate to a rigorous gaussian function.
Ideally, I would like to write a function along the lines of this pseudocode…
def make_node_image(measured_value, std_dev):
mean_circle_radius = sqrt(measured_value/pi)
image_circle_radius = sqrt((measured_value + 2*std_dev)/pi)
gradient_amplitude = 1/(std_dev*sqrt(2*pi))
gradient_fade = e^(-(r-mean_circle_radius)^2/(2*std_dev^2))
image_gradient = gradient_amplitude*gradient_fade
***generate_image_from_gradient***
***scale_and_clip_image_to_image_circle_radius***
return image
The two starred bits are where I need help; I’d appreciate any suggestions, thanks!
One way to accomplish this is with
matplotlib, as you suggested in your tags. To do this, I wouldimage_gradient.figurethat has a square shape with size in inches correlated to the radius of your circle (image_circle_radius), for which you’ll need to keep in mind the figure’s dots-per-inch (fig.dpi)axeswith no margins, no frame and no ticks (fig.add_axes([0,0,1,1],frameon=False, xticks=[], yticks=[])imshowto plot the array as an image.set_clip_path()method to clip theAxesImagecreated by theimshowcall.This approach is inspired by a matplotlib example.
Here is an attempt at doing what prescribe:
This results in:
gradient_fade, though off hand I don’t know what it is.