Hello everyone,
Happy New Year!
I am a total Newbie (both to Anvil and to Plotly), still on my free account, running into an issue I can’t get my head around, despite lots of searching and trying to make sense of online sources. I need your help!
What I’m trying to do:
I am trying to use fillpatterns in plotly graphs in my client side code.
What I’ve tried and what’s not working:
In Jupyter Notebook, the following code
import math
import plotly.graph_objects as go
data = [(abs(round((math.sin(math.pi/30*x))*120,1))) for x in range(0,100)]
x = [x for x in range(0,100)]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=x,
y=data,
line=dict(width=3.0, color='red'),
fillpattern=dict(fgcolor='red', fillmode='replace', shape="x"),
stackgroup="one")
)
fig.show()
produces a nice
However, trying the same code inside my client side Anvil Form (with a Plot element self.plot_1) gives me a
TypeError: ‘WrappedObject’ object is not callable
error in the line with
fig.add_trace(go.Scatter(
modifying it to an Anvil style
from ._anvil_designer import Form1Template
from anvil import *
import math
import plotly.graph_objects as go
class Form1(Form1Template):
def __init__(self, **properties):
self.init_components(**properties)
data = [(abs(round((math.sin(math.pi/30*x))*120,1))) for x in range(0,100)]
x = [x for x in range(0,100)]
plots = []
plots.append(
go.Scatter(
x=x,
y=data,
line=dict(width=3.0, color='red'),
fillpattern=dict(fgcolor='red', fillmode='replace', shape="x"),
stackgroup="one"
))
self.plot_1.data = plots
(where self.plot_1 is a Plot element dragged onto the form in the Anvil UI) I get
which is missing the patterns.
Is there a way to make these fillpatterns work in Anvil, ideally on the client side?
More generally:
Most Plotly examples e.g. for things like Sankey diagrams, use the
fig = go.Figure()
way of doing plotly. Is there a way to make this work with Anvil?
Thanks for any tips!
Tobi