[Docs] RuntimeError: Bad RGB in plot

According to the documentation openmc.Universe — OpenMC Documentation, for parameter colors of method openmc.Universe.plot, red, green, blue, and alpha should all be floats in the range [0.0, 1.0]. But the following code results into a runtime error Bad RGB in plot:

geometry.root_universe.plot(
    width=(200, 200),
    pixels=(800, 800),
    origin=(0, 0, 250),
    color_by="material",
    colors={water:(0.,0.,1.)},
)

It seems that rgb should be int in the range [0,255]. I don’t know whether it originates from a breaking change of matplotlib or openmc. Maybe we should update the docs?

Furthermore, does this API really support rgba? It seems that a RGBA 4-tuples will always raise runtime error

Thanks for pointing this out @kingyue. We recently changed what happens under the hood when you call Universe.plot. Before it used to be generated/colored by matplotlib, but now it relies on the openmc executable to produce a png and then simply shows that png and the coloring options are slightly more restrictive as you’ve found. I’ll get the documentation updated. You are correct that alpha channel is not supported.

Piggybacking on to this discussion as it involves issues with RGB etc.

I’ve just been looking into the Python universe.plot plotting.

@Shimwell, them outlines are rad
@gridley, auto-legend is nice and handy, but I can’t seem to get it working with RGB e.g.: (10, 255, 20), it complains that it’s not RGBA, then I make it RGBA and it doesn’t like that either. I can only get it working with color names e.g.:‘blue’
A consequence/constraint of the patches routine?

I did have a method of getting openmc to generate matplotlib plots using RGB values that I coded up and put into a prototyping package.

Recently I’ve been porting functionality across from that package to openmc and I was planning to tackle this RGB topic at some point.

Thanks for the heads up! This PR fixes that behavior. I didn’t realize matplotlib expected RGB values to range from 0-1 rather than 0-255.

2 Likes

The RGB legend fix made by @gridley has now been merged into the develop branch