forked from StructuredLabs/preswald
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for matplotlib issue StructuredLabs#71
- Loading branch information
1 parent
7c66df5
commit 921d915
Showing
11 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
secrets.toml | ||
.preswald_deploy | ||
.env.structured |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Preswald Project | ||
|
||
## Setup | ||
1. Configure your data connections in `preswald.toml` | ||
2. Add sensitive information (passwords, API keys) to `secrets.toml` | ||
3. Run your app with `preswald run hello.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from preswald import matplotlib | ||
import numpy as np | ||
|
||
x = np.linspace(0, 50, 100) | ||
sin = np.sin(x) | ||
cos = np.cos(x) | ||
tan = np.tan(x) | ||
|
||
plt = matplotlib.plt | ||
plt.figure(figsize=(10, 6)) | ||
|
||
plt.plot(x, sin, 'b--', label='sin(x)', linewidth=2) | ||
plt.plot(x, cos, 'r--', label='cos(x)', linewidth=2) | ||
plt.plot(x, tan, 'g--', label='tan(x)', linewidth=2) | ||
|
||
plt.title('Sinus Waves', fontsize=16, pad=20) | ||
|
||
plt.xlabel('X axis', fontsize=12) | ||
plt.ylabel('Y axis', fontsize=12) | ||
|
||
plt.legend(loc='upper right', fontsize=10) | ||
|
||
plt.grid(True, linestyle='--', alpha=0.5) | ||
|
||
plt.xlim(0, 10) | ||
plt.ylim(-1.5, 1.5) | ||
|
||
matplotlib(plt.gcf(), format='svg') |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[project] | ||
title = "Preswald Project" | ||
version = "0.1.0" | ||
port = 8501 | ||
|
||
[branding] | ||
name = "Preswald Project" | ||
logo = "images/logo.png" | ||
favicon = "images/favicon.ico" | ||
primaryColor = "#F89613" | ||
|
||
[data.csv] | ||
type = "csv" | ||
path = "data/sample.csv" | ||
|
||
[logging] | ||
level = "INFO" # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL | ||
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "preswald-app" | ||
version = "0.1.0" | ||
description = "A Preswald application" | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
"preswald" | ||
] | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["."] | ||
|
||
[tool.black] | ||
line-length = 88 | ||
target-version = ['py38'] | ||
|
||
[tool.isort] | ||
profile = "black" | ||
multi_line_output = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
|
||
const MatplotlibComponent = ({ data }) => { | ||
const { image, format } = data; | ||
if (format === 'svg') { | ||
// For SVG, we need to decode and render it as HTML | ||
const decodedSvg = atob(image); | ||
return ( | ||
<div | ||
className="w-full overflow-hidden rounded-lg shadow-sm" | ||
dangerouslySetInnerHTML={{ __html: decodedSvg }} | ||
/> | ||
); | ||
} | ||
|
||
// For PNG and other formats, use img tag | ||
return ( | ||
<div className="w-full overflow-hidden rounded-lg shadow-sm"> | ||
<img src={`data:image/${format};base64,${image}`} alt="Matplotlib Plot" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MatplotlibComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters