Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:27:56+00:00 2026-05-26T19:27:56+00:00

I am producing a simple, Python-based program that produces graphviz graphs as output. I

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:27:57+00:00Added an answer on May 26, 2026 at 7:27 pm

    One way to accomplish this is with matplotlib, as you suggested in your tags. To do this, I would

    1. use numpy to create an NxN array to represent image_gradient.
    2. create a figure that 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)
    3. create an axes with no margins, no frame and no ticks (fig.add_axes([0,0,1,1],frameon=False, xticks=[], yticks=[])
    4. use imshow to plot the array as an image.
    5. create a circle, with center and radius in units of DPI
    6. use the set_clip_path() method to clip the AxesImage created by the imshow call.

    This approach is inspired by a matplotlib example.

    Here is an attempt at doing what prescribe:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.path as path
    import matplotlib.patches as patches
    
    pi = np.pi
    sqrt = np.sqrt
    exp = np.exp
    
    def make_node_image(measured_value, std_dev, coverage="0.96",imageID=1):
    
        DPI = 100
        TODPI=1
        MINSIZE = 50 # in DPI
        MAXSIZE = 400 # in DPI
        MAXAMPLITUDE = .005
    
        # make radius,std_dev  values in grid units
        mean_circle_radius = int(sqrt(measured_value/pi)/TODPI)
        image_circle_radius = int(sqrt((measured_value + 2*std_dev)/pi)/TODPI)
        if image_circle_radius < MINSIZE:
            raise Exception("image_circle_radius too small!")
        if image_circle_radius > MAXSIZE:
            raise Exception("image_circle_radius too large!")
    
        grid_std_dev = std_dev/TODPI
    
        gradient_amplitude = 1/(std_dev*sqrt(2*pi))/MAXAMPLITUDE
        gradient_fade = np.zeros([2*image_circle_radius,
                                  2*image_circle_radius])
        for ix in range(2*image_circle_radius):
            for iy in range(2*image_circle_radius):
                r = sqrt((ix-image_circle_radius)**2
                         +(iy-image_circle_radius)**2)
                gradient_fade[ix,iy] = exp(
                    -(r-mean_circle_radius)**2
                     /(2*grid_std_dev**2))
    
        image_gradient = gradient_amplitude*gradient_fade
    
        fig = plt.figure(figsize=(2*image_circle_radius/DPI,
                                  2*image_circle_radius/DPI),dpi=DPI)
    
    
        ax = fig.add_axes([0,0,1,1],frameon=True, xticks=[], yticks=[])
    
        #***generate_image_from_gradient***
        im = ax.imshow(image_gradient,vmin=0,vmax=1)
    
        patch = patches.Circle((image_circle_radius,image_circle_radius), 
                               radius=image_circle_radius,fc='white')
    
        #***scale_and_clip_image_to_image_circle_radius***
        im.set_clip_path(patch)
    
        name = 'circImage%d.png'%imageID
        fig.savefig(name)
    
        return name
    
    make_node_image(90000*pi,100)
    

    This results in:

    enter image description here

    1. The circle seems to be clipped at the edges.
    2. The is almost certainly vectorized approach to build gradient_fade, though off hand I don’t know what it is.
    3. This feels kludgy, and I really hope someone provides a more elegant answer.
    4. Obviously the above code is just a starting point and someone can definitely improve upon it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am producing graphs in a Python program, and now I need to visualize
This simple code is not producing any sound on a couple of machines that
I have a top level widget that is producing a syntax error in python.
I have a simple piece of a program thats currently producing some memory leaks
I wrote a simple map reduce job that would read in data from the
Are there any portable open source libraries that support sample-based synthesis and encapsulate producing
My program seems to be producing some -0 values in place of values that
I would like to have an ordered list that has the text on the
How would you go about producing reports by user selected date ranges in a
I wrote the following class for producing monitoring output within an extra window. Unfortunately

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.