# What are the best practices to put a very simple plot on custom \`show\`s of the types in a package?

**URL:** <https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [April 20, 2024, 1:25am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260 "2024-04-20T01:25:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 20, 2024, 1:25am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/1 "2024-04-20T01:25:41Z")

</div>

Hi all,

I would like to put a very simple plot on the output of custom `show(::IO, ::MIME "image/svg+xml", ::MyType)`. (In my case 2-d line and scatter plots are sufficient.)  
It is intended not only to help the user understand the object but also to test the package.

I have been writing scripts to generate SVGs for such purposes.  
(As a side note, I am a maintainer of ProfileSVG.jl. I am eagerly awaiting more maintainers!)  
However, that does not seem to be a very good practice in terms of reusability.

We have a variety of plotting tools, many of which have heavy dependencies and are costly.  
The reason I want to customize `show`, in the first place, is because I want to see the object without using plotting packages.  
Package extensions (weakdeps) solve the dependency problem, but not the cost.

The type of tools that use JavaScript libraries tend to have fewer dependencies and smaller costs on the Julia side. However, I would prefer static or standalone SVGs. (_Additional_ interactivity would be welcome, though.)

In short, I am looking for an SVG version of (early) UnicodePlots.jl.  
I do not want to start a ”holy war" here, but I hope there are many possibilities.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [April 21, 2024, 2:36am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/2 "2024-04-21T02:36:41Z")

</div>

So you want to have some “simple” plots that don’t come with a heavy dependency? I suggest you take a look at the different plotting paclages Julia has to offer:

> [@Comparison of plotting packages](https://discourse.julialang.org/t/comparison-of-plotting-packages/99860/2):
>
> Summary of Plotting Packages [Plots.jl](https://docs.juliaplots.org/) is the most used. It’s probably the most documented, used in the most tutorials, and is used in many videos. Pros: Its main draw is that it has a lot of plugins to other packages through its recipes system, which means that a lot of odd things like plot(sol::ODESolution) or showing the sparsity of a BandedMatrix just works. With all of these integrations, it’s normally what I would recommend first to newcomers since they will generally get the most done …

Maybe VegaLite.jl or PlotlyLight.jl is a good fit for your project?

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 21, 2024, 2:57am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/3 "2024-04-21T02:57:18Z")

</div>

Thanks for the information.

> However, I would prefer static or standalone SVGs. (_Additional_ interactivity would be welcome, though.)

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 21, 2024, 4:47am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/4 "2024-04-21T04:47:29Z")

</div>

From another perspective, is there any value in generalizing plot generation scripts for specific packages?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [April 21, 2024, 5:39am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/5 "2024-04-21T05:39:04Z")

</div>

I am not very familiar with it but perhaps this is what you’d want to do?

> **[Plots.jl/RecipesBase at master · JuliaPlots/Plots.jl](https://github.com/JuliaPlots/Plots.jl/tree/master/RecipesBase)**
>
> Powerful convenience for Julia visualizations and data analysis - JuliaPlots/Plots.jl

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 21, 2024, 6:08am UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/6 "2024-04-21T06:08:36Z")

</div>

Well, as the name implies, they are recipes, not finished dishes (plots).

Of course, one proven practice is for the package to provide only the recipe and leave the plot generation to the end-user and the user-preferred backend.

---

<div class="post-metadata">

**Author:** ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)\
**Post date:** [April 23, 2024, 3:43pm UTC](https://discourse.julialang.org/t/what-are-the-best-practices-to-put-a-very-simple-plot-on-custom-show-s-of-the-types-in-a-package/113260/7 "2024-04-23T15:43:52Z")

</div>

Since most of the color specification strings are compatible with SVG, I don’t see the need to even depend on ColorTypes.jl and Colors.jl.  
It doesn’t matter if it is a symbol or a duck if it can be converted to a color string.

```julia
struct SomethingLike{S,T}
    val::T
end
SomethingLike{S}(val::T) where {S,T} = SomethingLike{S,T}(val)

str(s::SomethingLike) = string(s.val)

const ColorLike{T} = SomethingLike{:color,T}

```

 ![minimalsvg](https://global.discourse-cdn.com/julialang/original/3X/c/0/c099bc0516f9418482af6879522dcfbaa16c1078.png)  
Of course, this is a joke program. 🙂
