Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestbao committed Oct 26, 2023
1 parent 9c86d46 commit 042c198
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion examples/multimedia/rgb2gray.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import io # Python's native

import PIL # the Python Image Library
import IPython
import funix

@funix.funix(
title="Convert color images to grayscale images",
)
def gray_it(image: funix.hint.BytesImage) -> funix.hint.Image:
def gray_it(image: funix.hint.BytesImage) -> IPython.display.Image:
img = PIL.Image.open(io.BytesIO(image))
gray = PIL.ImageOps.grayscale(img)
output = io.BytesIO()
Expand Down
47 changes: 24 additions & 23 deletions examples/slider_table_plot.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
from typing import List # Python native
import matplotlib.pyplot as plt # the de facto standard for plotting in Python
from matplotlib.figure import Figure # the matplotlib figure class

import matplotlib.figure, matplotlib.pyplot# the de facto standard for plotting in Python

import funix
@funix.funix(widgets={"a": "sheet", "b": ["sheet", "slider[0,5,0.2]"]})
def table_plot(
a: List[int] = [5, 17, 29], b: List[float] = [3.1415, 2.6342, 1.98964]
) -> Figure:
fig = plt.figure()
plt.plot(a, b)
return fig

# @funix.funix(widgets={"a": "sheet", "b": ["sheet", "slider[0,5,0.2]"]})
# def table_plot(
# a: List[int] = [5, 17, 29], b: List[float] = [3.1415, 2.6342, 1.98964]
# ) -> Figure:
# fig = matplotlib.pyplot.figure()
# matplotlib.pyplot.plot(a, b)
# return fig


# Future Implementation
# New Implementation after FEP 11

# import pandas # the de facto standard for tabular data in Python
# import pandera # the typing library for pandas dataframes
import pandas # the de facto standard for tabular data in Python
import pandera # the typing library for pandas dataframes

# class MySchema(pandera.DataFrameModel):
# a: pandera.typing.Series[int]
# b: pandera.typing.Series[float]
class MySchema(pandera.DataFrameModel):
a: pandera.typing.Series[int]
b: pandera.typing.Series[float]

# funix.funix()
# def table_plot(df: pandera.typing.DataFrame[MySchema] = \
# pandas.DataFrame({"a": [5, 17, 29],
# "b": [3.1415, 2.6342, 1.98964]})
# ) -> Figure:
# fig = plt.figure()
# plt.plot(a, b)
# return fig
@funix.funix()
def table_plot(df: pandera.typing.DataFrame[MySchema] = \
pandas.DataFrame({"a": [5, 17, 29], # default values
"b": [3.1415, 2.6342, 1.98964]})
) -> matplotlib.figure.Figure:
fig = matplotlib.pyplot.figure()
matplotlib.pyplot.plot(df["a"], df["b"])
return fig

0 comments on commit 042c198

Please sign in to comment.