# Plots and truncating numbers?

**URL:** https://discourse.julialang.org/t/plots-and-truncating-numbers/25893
**Category:** Visualization
**Created:** [July 1, 2019, 12:51pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893 "2019-07-01T12:51:54Z")
**Posts on this page:** 10
**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: [July 1, 2019, 12:51pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/1 "2019-07-01T12:51:54Z")

</div>

I’m plotting tiny subplots in a 4x4 matrix. Some of the subplots contain a large number of digits… making the plot really ugly:

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

I’m trying to map the `trunc()` function on the plots, e.g.,

```julia
x = ...
Y = ...
fg = []
for i in 1:15
    push!(fg,plot(x,trunc.(Y[i];digits=2)))
end
plot(fg...)

```

But it seems arbitrary whether the values on the ordinate axes are displayed with 2 digits or 1 digit or a large number of digits, etc.

Is there a way around this?

---

<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: [July 1, 2019, 1:00pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/2 "2019-07-01T13:00:01Z")

</div>

Please make an MWE which includes, among other things, the backend.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<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: [July 1, 2019, 1:42pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/3 "2019-07-01T13:42:15Z")

</div>

I’ll _try_ to construct an MWE… not trivial – I plot results from the loss function of fitting various parameters to experimental data. If I use “nice” functions, the problem doesn’t appear, I think.

---

<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: [July 1, 2019, 2:05pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/4 "2019-07-01T14:05:32Z")

</div>

I suspect this is coming from an axes where numbers vary little. Also, the backend info may be useful, since it is not clear from your post.

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [July 1, 2019, 2:09pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/5 "2019-07-01T14:09:41Z")

</div>

I think this problem is solved. It was related to `Showoff.jl` …

[https://github.com/JuliaGraphics/Showoff.jl/commit/8502c2ec11f93c4f50c609ff4168aab31154b39d](https://github.com/JuliaGraphics/Showoff.jl/commit/8502c2ec11f93c4f50c609ff4168aab31154b39d)

---

<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: [July 1, 2019, 2:21pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/6 "2019-07-01T14:21:33Z")

</div>

Ok? I ran a `Pkg.update()` just before I took the screen shots today. Maybe the fix hasn’t been pushed out yet.

---

<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: [July 1, 2019, 2:24pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/7 "2019-07-01T14:24:21Z")

</div>

I _thought_ I used PyPlot… I then discovered that the statement was `pyplot` instead of `pyplot()` resulting in a defaulting to GR.

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [July 1, 2019, 2:33pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/8 "2019-07-01T14:33:35Z")

</div>

You can specify a function to format your ticks

```julia
f(x)= exp(x)
using Plots,Formatting
gr()
plot(f,0.0:0.01:1.5,yscale=:log10,xscale=:identity,
    xformatter=x->format( x, precision=2 ),
    yformatter=x->format( log(x), precision=2 ))

```

---

<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: [July 2, 2019, 7:41am UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/9 "2019-07-02T07:41:50Z")

</div>

This is a bug that has been fixed - it may not have been released yet.

---

<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: [July 2, 2019, 12:41pm UTC](https://discourse.julialang.org/t/plots-and-truncating-numbers/25893/10 "2019-07-02T12:41:32Z")

</div>

> [@feanor12](#):
>
> xformatter=x-\>format( x, precision=2 ),

Superb! Looks beautiful!!
