tum-pbs / PhiFlow

A differentiable PDE solving framework for machine learning
MIT License
1.43k stars 193 forks source link

Plotting overlaying fields in different colors. #112

Closed nathanLaubeuf closed 1 year ago

nathanLaubeuf commented 1 year ago

Cannot plot fields wrapped with vis.overlay in different colors since f03e6bd8019253604e855e1edbf058cfa2a6f50e. This used to be supported when color was an attribute of the field. Can it be fixed, maybe with a different indexing of vis.plot's color argument?

holl- commented 1 year ago

The easiest way to do it is to stack your data along a channel dimension that is not called 'vector'. Then the different components will automatically get different colors.

plot(CenteredGrid(Noise(colors='col1,col2'), x_axis=10))
plot(math.random_uniform(instance(x=10), channel(colors=2, vector='x,y')))

You can additionally specify the colors directly, either as cycle indices or via hex code:

plot(CenteredGrid(Noise(colors='col1,col2'), x_axis=10), color=wrap([2, 3], channel('colors')))
plot(math.random_uniform(instance(x=10), channel(colors=2, vector='x,y')), color=wrap(["#000000", "#FF0000"], channel('colors')))

Does that solve your issue?

nathanLaubeuf commented 1 year ago

No luck there. I'm trying to plot 3 populations of points with different sizes.

rock = math.random_uniform(instance(x=10), channel(vector='x,y'))
paper = math.random_uniform(instance(x=5), channel(vector='x,y'))
scissors = math.random_uniform(instance(x=7), channel(vector='x,y'))

particles = math.stack((rock, paper, scissors), channel(colors=3))

vis.plot(particles, color=wrap(["#0000FF", "#FF0000", "#00FF00"], channel(colors=3)))

This snippet breaks with a NotImplementedError from particles being a non-uniform tensor.

holl- commented 1 year ago

Okay, I got it to work by replacing math.stack by math.layout. This runs on the latest develop version at least.

The stack version unfortunately results in non-uniform tensors for which not all operations are supported yet. The layout is basically just like a list with a named dimension.

nathanLaubeuf commented 1 year ago

That fixed it. Thanks!