| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This example demonstrates how to use the plotly_static crate with clap to create a command-line tool for exporting Plotly plots to static images.
Export a plot from a JSON file (using Chrome driver):
cargo run --example generate_static --features chromedriver -- -i sample_plot.json -o my_plot -f pngExport a plot from a JSON file (using Firefox/Gecko driver):
cargo run --example generate_static --features geckodriver -- -i sample_plot.json -o my_plot -f pngExport a plot from stdin:
cat sample_plot.json | cargo run --example generate_static --features chromedriver -- -f svg -o outputThe example supports two different web drivers for rendering plots:
You must specify one of these features when running the example. For example:
# Use Chrome driver
cargo run --example generate_static --features chromedriver -- -i plot.json -o output.png
# Use Firefox driver
cargo run --example generate_static --features geckodriver -- -i plot.json -o output.pngThe example uses env_logger for logging. You can enable different log levels using the RUST_LOG environment variable:
# Enable info level logging
RUST_LOG=info cargo run --example generate_static --features chromedriver -- -i sample_plot.json -o my_plot -f png
# Enable debug level logging for more verbose output
RUST_LOG=debug cargo run --example generate_static --features geckodriver -- -i sample_plot.json -o my_plot -f png
# Enable all logging levels
RUST_LOG=trace cargo run --example generate_static --features chromedriver -- -i sample_plot.json -o my_plot -f pngExport to PNG with custom dimensions:
cargo run --example generate_static --features chromedriver -- -i sample_plot.json -o plot -f png --width 1200 --height 800Export to SVG from stdin:
echo '{"data":[{"type":"scatter","x":[1,2,3],"y":[4,5,6]}],"layout":{}}' | \
cargo run --example generate_static --features geckodriver -- -f svg -o scatter_plotExport to PDF with high resolution:
cargo run --example generate_static --features chromedriver -- -i sample_plot.json -o report -f pdf --width 1600 --height 1200 -s 2.0The input JSON should follow the Plotly figure specification:
{
"data": [
{
"type": "surface",
"x": [1.0, 2.0, 3.0],
"y": [4.0, 5.0, 6.0],
"z": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
}
],
"layout": {},
"config": {}
}| Back | FazBrowse Home | New Git URL |