Skip to content

Commit

Permalink
Create matplotlib grid example
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Jan 30, 2024
1 parent af9826a commit 7218e94
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions mesop/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
error_no_stateclass_decorator as error_no_stateclass_decorator,
)
from mesop.examples import generator as generator
from mesop.examples import grid as grid
from mesop.examples import index as index
from mesop.examples import integrations as integrations
from mesop.examples import nested as nested
Expand Down
10 changes: 10 additions & 0 deletions mesop/examples/grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import mesop as me


@me.page(path="/grid")
def app():
with me.box(style=me.Style(display="grid", grid_template_columns="1fr 1fr")):
me.text("hi1")
me.text("hi2")
me.text("hi3")
me.text("hi4")
3 changes: 3 additions & 0 deletions mesop/examples/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from mesop.examples.integrations import (
matplotlib as matplotlib,
)
from mesop.examples.integrations import (
matplotlib_grid as matplotlib_grid,
)
1 change: 0 additions & 1 deletion mesop/examples/integrations/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ def app():

me.text("Resize plot:")
me.plot(fig, style=me.Style(width=200, height=200))
me.plot(fig)
54 changes: 54 additions & 0 deletions mesop/examples/integrations/matplotlib_grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from matplotlib.figure import Figure

import mesop as me


@me.page(path="/integrations/matplotlib_grid")
def app():
with me.box(
style=me.Style(
display="grid",
grid_template_columns="1fr 1fr",
gap="16px",
padding=me.Padding(
top=16,
left=16,
right=16,
bottom=16,
),
overflow_y="auto",
)
):
graph()
graph()
graph()
graph()


def graph():
border_side = me.BorderSide(width=1, color="#ddd", style="solid")
with me.box(
style=me.Style(
background="#fff",
border=me.Border(
top=border_side,
right=border_side,
bottom=border_side,
left=border_side,
),
border_radius=16,
padding=me.Padding(
top=16,
left=16,
right=16,
bottom=16,
),
)
):
# Create matplotlib figure without using pyplot:
fig = Figure()
ax = fig.subplots() # type: ignore
ax.plot([1, 2]) # type: ignore

me.text("Example using matplotlib:")
me.plot(fig, style=me.Style(width="100%"))

0 comments on commit 7218e94

Please sign in to comment.