# 2D Plots... some missing possibilities?

**URL:** <https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894>\
**Category:** Visualization\
**Created:** [August 4, 2018, 3:27pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894 "2018-08-04T15:27:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 4, 2018, 3:27pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/1 "2018-08-04T15:27:53Z")

</div>

I’m continuing to explore Plots (mainly 2D for now). Some useful things are missing, others are perhaps only hard to find?

- Figure title – has not been implemented yet. There are some workarounds, but these are somewhat clumsy. Currently, “title” gives the subplot title, as far as I know.
- Specifying several columns in legend panel (like PyPlot can) – it does not always look good to have a long column…
- Support for LaTeX math: PyPlot backend has good support, GR less so. GR LaTeX math looks ugly in the Atom/Juno editor, and in IJulia (perhaps better in saved files?). Also, the GR support of LaTeX is incomplete: it seems to work in title, xlabel, and ylabel, but not in labels.
- If I try to use PyPlot as backend in Atom/Juno, I get an error message related to loading a C-library. GR, on the other hand, works (but with limited LaTeX support…)
- Grid…:  
– How to specify color, linewidth, line style, etc of grid lines?  
– How to specify spatial gap between grid lines? E.g., for Bode plots, the standard is to use equidistant gap between gridlines for the integer exponents (major grid), and logarithmic gap within each of the major grid lines (minor grid). Is this possible (ControlSystems package seems to give equidistant grid lines, only), or do I have to use PyPlot for now to achieve this?

OK – I really appreciate all the work going into visualization tools. And I know there is hectic activity related to v. 0.7/v.1.0. So please do not read this as critique: I rather ask to find out what is currently possible (and what may be in planning…).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 5, 2018, 6:42am UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/2 "2018-08-05T06:42:29Z")

</div>

> [@BLI](#):
>
> Support for LaTeX math

If integration with LaTeX documents is important for you, consider exploring

> **[GitHub - KristofferC/PGFPlotsX.jl: Plots in Julia using the PGFPlots LaTeX...](https://github.com/KristofferC/PGFPlotsX.jl)**
>
> Plots in Julia using the PGFPlots LaTeX package. Contribute to KristofferC/PGFPlotsX.jl development by creating an account on GitHub.

which is just a thin layer over the LaTeX package `pgfplots`, so it relies on the features and the documentation of the latter. It can also do everything else you asked for. But note that it is not integrated into Plots.jl, so you wont be able to switch backends so easily, and you really have to like LaTeX 😉

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 6, 2018, 11:03pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/3 "2018-08-06T23:03:34Z")

</div>

it would be nice if you would turn each of these points into issues on the Plots.jl repo - that will make it easier to address each of them in turn, associate discussion and code suggestion to them etc. Just please first search Plots.jl first to see if some of them are already open issues, then comment on the issue instead of openting a new one.

Thanks!

---

<div class="post-metadata">

**Author:** ![mfalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfalt/32/12467_2.png) [@mfalt](https://discourse.julialang.org/u/mfalt)\
**Post date:** [August 9, 2018, 9:28pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/4 "2018-08-09T21:28:21Z")

</div>

We actually have the minor grids in ControlSystems.jl (at least if I understand you correctly). I’m not sure which backends show this properly. Image found below, and an example of how it can be done is [here](https://github.com/JuliaControl/ControlSystems.jl/blame/master/src/plotting.jl#L53)  
 ![](https://global.discourse-cdn.com/julialang/original/3X/f/c/fcff4392c8e33c93ec8cdc7e4fdd368f91df0cf0.png)  
The

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 9, 2018, 9:41pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/5 "2018-08-09T21:41:11Z")

</div>

## Great: you understand me correctly wrt. “minor grid”. Is it possible to specify line type, line thickness, color, etc. for the grids (major, minor)?

This “minor grid” didn’t show up in my IJulia notebook… I’ll have to check what backend I used. I know that PyPlot can have this “minor grid”. I’ll check tomorrow.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 10, 2018, 7:26am UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/6 "2018-08-10T07:26:38Z")

</div>

OK – I’ve checked: neither of backends “pyplot” or “gr” give the “minor logarithmic grid” – unless there is a way to set it. Also, I notice your bodeplots are somewhat strange in the way it displays the numbers along the abscissa. Anyway, here is what I get using bodeplot:

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

Some years ago, I played around with Python/pyplot. The following example illustrates the possibility I’m looking for:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/7/673163b1cd5cc6fc3b506fb569cfd49d14fe3948.png)

The following code was used to produce this:

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

The possibility to specify the grid color/thickness/line style is perhaps more for nostalgic reasons… I remember when, as a student, I had to buy a notebook of bode plot sheets – the color of the grid was typically some shade of green or orange…

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 10, 2018, 7:49am UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/7 "2018-08-10T07:49:38Z")

</div>

Do consider ordering this into issues on Plots.  
If you go to the repo, you’ll see that minor ticks were just implemented on master for gr() [https://github.com/JuliaPlots/Plots.jl/pull/1596](https://github.com/JuliaPlots/Plots.jl/pull/1596) (and you get them natively if you use plotlyjs()).  
You can adjust the grid using the `grid` magical argument, e.g. `grid = (:green, :dot, 2, 1.)`

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 10, 2018, 12:46pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/8 "2018-08-10T12:46:14Z")

</div>

Thanks for tip on grid.

I still don’t get logarithmic grid for GR and PyPlot… I tried to install PlotlyJS on my system (from IJulia); didn’t work.

---

<div class="post-metadata">

**Author:** ![mfalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfalt/32/12467_2.png) [@mfalt](https://discourse.julialang.org/u/mfalt)\
**Post date:** [August 10, 2018, 3:18pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/9 "2018-08-10T15:18:35Z")

</div>

My fault here, I didn’t test this properly on the last tagged version of ControlSystems. The plotting has been changed a lot since the last version of ControlSystems (as much of the rest of the package). For example we now use Plots recipes. The plot I showed is generated from the “master” branch of ControlSystems.jl.

The printing on the axis depends on how the backend interprets the strings “10^{-1}” and similar. We have a special case for the GR backend where they are encoded as `LaTexString`.

It should be noted that the minor grids are not printed if there are already too many major grids, and we don’t know how to have different properties on minor and major grids. If you have any good ideas, feel free to create a pull request onto the “autodiff” branch of ControlSystems.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 10, 2018, 3:23pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/10 "2018-08-10T15:23:55Z")

</div>

OK… I’m trying to decode the command `grid = (:green, :dot, 2, 1.)`. From the `Plots` documentation:

```julia
plot(y, line = (:steppre, :dot, :arrow, 0.5, 4, :red))

plot(y, seriestype = :steppre,
        linestyle = :dot,
        arrow = :arrow,
        linealpha = 0.5,
        linewidth = 4,
        linecolor = :red)

```

So… I’m guessing that:

```julia
plot(y, grid= (:green, :dot, 2, 1.))

```

could be spelt out as:

```julia
plot(y, gridlinestyle = :dot,
        gridalpha = 1.,
        gridlinewidth = 2,
        gridlinecolor = :green)

```

I have not been able to guess how to achieve logarithmic scaling of the grid with `xcale=:log10`, though…

Thus, with `julia> pyplot()`, the following code:

```julia
sys = tfg("2*(1-3*s)/(1+0.1*s)/(1+10*s)")
mag,phase,w = bode(sys);
#
plot(w,[20*log10.(mag[:][:][:]),phase[:][:][:]],xscale=:log10,
    linecolor=[:red :blue],layout=(2,1),linewidth=1.5,linealpha=0.9)
plot!(title=["Bode plot" ""],xlabel=["" "Frequency [rad/s]"])
plot!(ylabel=["Magnitude (dB)" "Phase (deg)"])
plot!(gridcolor=:green,gridlinestyle=:dot,gridlinewidth=1,
    gridalpha=0.8)

```

leads to:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/6/66c2e2fa54c1fa15d5588a6dc1d560e7bb09ddc2.png)

Perhaps the nice, logarithmic “minor grid” as shown for pyplot in a previous message will appear in a later version of Plots?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 10, 2018, 3:29pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/11 "2018-08-10T15:29:52Z")

</div>

Hm… my PyPlot code shown above (I did this ca. 2011-2012) automatically includes log10 minor grid, I guess. I assume that the statement `plt.grid(True, "both", color="green")` is interpreted as follows: include grid (`True`), use both major grid and minor grid (`"both"`), and `"green"` is obvious…

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 10, 2018, 3:32pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/12 "2018-08-10T15:32:44Z")

</div>

Have you checked out Plots master?

---

<div class="post-metadata">

**Author:** ![mfalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfalt/32/12467_2.png) [@mfalt](https://discourse.julialang.org/u/mfalt)\
**Post date:** [August 10, 2018, 3:40pm UTC](https://discourse.julialang.org/t/2d-plots-some-missing-possibilities/12894/13 "2018-08-10T15:40:07Z")

</div>

The minor grids is implemented in the ControlSystems package (but only on “master” branch). There you are also able to send in any extra commands that you would send to plots, such as `gridlinestyle = :dot`. Example

```julia
bodeplot(sys, gridstyle=:dot)

```

However, since it plots both the phase and magnitude, it is sometimes a bit ambiguous. There is therefore an alternative way to use the features we have, which is using the seriestype = :bodemag/:bodephase  
Example:

```julia
Plots.plot(w, mag[:], seriestype = :bodemag, gridstyle = :dot)

```

Again, these currently only work on ControlSystems “master” branch, which you can get with  
`Pkg.checkout("ControlSystems", "master")`

**Edit: there is a function that computes the ticks (both major and minor) that you can use to customize you plots.** Example

```julia
s = tf("s")
sys = -6*(s-0.33)/(s+10)/(s+0.1)
w = logspace(-1,1)
mag, phase, w = bode(sys, w)
ticks = ControlSystems.getLogTicks(w)
Plots.plot(w, mag[:], xticks=ticks, xscale=:log10)

```

it returns something like

```julia
([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], String["10^{-1}", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "10^{0}", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "\$ \$", "10^{1}"])

```
