# Call for Plots examples

**URL:** <https://discourse.julialang.org/t/call-for-plots-examples/78206>\
**Category:** Visualization\
**Tags:** documentation, plots\
**Created:** [March 21, 2022, 11:48am UTC](https://discourse.julialang.org/t/call-for-plots-examples/78206 "2022-03-21T11:48:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)\
**Post date:** [March 21, 2022, 11:48am UTC](https://discourse.julialang.org/t/call-for-plots-examples/78206/1 "2022-03-21T11:48:15Z")

</div>

I’m not an experienced Plots user; every time when I use Plots I try to find an example that looks useful and try to modify it.

With the help of @BeastyBlacksmith we’ve finally set up the demo gallery using [DemoCards.jl](https://github.com/johnnychen94/DemoCards.jl), the latest version can be found in [User Gallery · Plots](https://docs.juliaplots.org/dev/user_gallery/). If you have interesting examples, it would be super helpful to add them there.

Building the Plots documentation is time-consuming (\>30mins) so here’s a brief guide on how you can build the demos within 3mins:

1. fork the [PlotDocs](https://github.com/JuliaPlots/PlotDocs.jl) repo
2. create a demo file in any sub-folder of `docs/user_gallery`
3. preview it using `DemoCards.preview_demos`
4. open a PR to PlotDocs when you’re satisfied.

The principle is quite simple: each Julia script corresponds to a demo.

* * *

# Example

Assume that we’re adding one demo “gr\_line\_plot.jl” to “docs/user\_gallery/misc” folder:

```julia
# ---
# title: Line plot
# author: Johnny Chen
# cover: assets/gr_line_plot.png
# date: 2022-03-21
# ---

using Plots

# This example shows how to use Plots to draw a line
plot(1:10)

## generating cover image on the fly
mkpath("assets") #src
png("assets/gr_line_plot.png") #src

```

The [DemoCards.jl YAML frontmatter](https://johnnychen94.github.io/DemoCards.jl/stable/quickstart/usage_example/julia_demos/1.julia_demo/#juliademocard_example) defines some of the basic information of this demo. Note that the cover image `"assets/gr_line_plot.png"` is generated at the end of the script.

There are some [Literate.jl markups](https://fredrikekre.github.io/Literate.jl/v2/fileformat/) here:

- leading `#` indicates a markdown line
- leading `##` indicates a Julia comment line
- trailing `#src` indicates that this won’t be shown in the generated demo

Here’s the result if you build this specific example:

```julia
julia> using DemoCards

julia> @time preview_demos("docs/user_gallery/misc/gr_line_plot.jl")
[ Info: SetupDemoCardsDirectory: setting up "user_gallery" directory.
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: ExpandTemplates: expanding markdown templates.
[ Info: CrossReferences: building cross-references.
[ Info: CheckDocument: running document checks.
[ Info: Populate: populating indices.
[ Info: RenderDocument: rendering document.
[ Info: HTMLWriter: rendering HTML pages.
[ Info: Redirect page URL: redirect docs-edit-link for demos in "user_gallery" directory.
[ Info: Clean up DemoCards build dir: "user_gallery"
  0.214942 seconds (71.78 k allocations: 10.674 MiB, 1.35% compilation time)
"/tmp/jl_hAAUbH/build/index.html"

```

then open the path in your favorite browser:

 ![1647864918(1)](https://global.discourse-cdn.com/julialang/original/3X/c/8/c83ac9db90427c74285bcc7b69fa44089e2ae56f.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/7/f7e0a91206a050d8af78645e8b01a622b46ca502.png)

Note that previewing the demo will be super-fast `0.2s` in this case since it doesn’t build the entire documentation.

You can also preview all demos in specific folder. For instance:

```julia
julia> @time preview_demos("docs/user_gallery/misc")
[ Info: SetupDemoCardsDirectory: setting up "user_gallery" directory.
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: ExpandTemplates: expanding markdown templates.
[ Info: CrossReferences: building cross-references.
[ Info: CheckDocument: running document checks.
[ Info: Populate: populating indices.
[ Info: RenderDocument: rendering document.
[ Info: HTMLWriter: rendering HTML pages.
[ Info: Redirect page URL: redirect docs-edit-link for demos in "user_gallery" directory.
[ Info: Clean up DemoCards build dir: "user_gallery"
  7.655850 seconds (9.66 M allocations: 422.247 MiB, 0.80% gc time, 0.65% compilation time)
"/tmp/jl_hAAUbH/build/index.html"

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5f07d1d533eec1e76e5415519cefb7bc919bf8c.png)

This is a bit slower since you need to build more demos.

When you’re satisfied with your demo, open a PR to the PlotDocs. For this trivial example, you can find the PR [here](https://github.com/JuliaPlots/PlotDocs.jl/pull/279)
