# Plot problem

**URL:** <https://discourse.julialang.org/t/plot-problem/11585>\
**Category:** Visualization\
**Created:** [June 11, 2018, 1:36pm UTC](https://discourse.julialang.org/t/plot-problem/11585 "2018-06-11T13:36:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcrbloch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcrbloch/32/4396_2.png) [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Post date:** [June 11, 2018, 1:36pm UTC](https://discourse.julialang.org/t/plot-problem/11585/1 "2018-06-11T13:36:49Z")

</div>

Many of my plots are cut off at the top. The commands are

```
plot(xlabel="s",ylabel="Re(f)")
plot!(T.s1,T.f1,color=:blue)
plot!(T.s2,T.f2,color=:blue)

```

---

<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:** [June 11, 2018, 2:00pm UTC](https://discourse.julialang.org/t/plot-problem/11585/2 "2018-06-11T14:00:36Z")

</div>

Could you post the resulting plots? It’s not a common problem, other people will get normal plots with those commands (if they know what T is). You should at least show an example and list your operating system, version info and so forth.

---

<div class="post-metadata">

**Author:** ![jcrbloch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcrbloch/32/4396_2.png) [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Post date:** [June 11, 2018, 3:12pm UTC](https://discourse.julialang.org/t/plot-problem/11585/3 "2018-06-11T15:12:45Z")

</div>

Dear Michael,

I thought I had included the png-output. I attach it again to this mail and hope that it will reach you. I made the lines thick to make the problem clearer, but it also happens for thinner lines.

versioninfo gives:

```julia
  Julia Version 0.6.2 Commit d386e40c17 (2017-12-13 18:08 UTC) Platform Info: OS: macOS (x86_64-apple-darwin14.5.0) CPU: Intel(R) Core(TM) i7-2760QM CPU @ 2.40GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, sandybridge)

```

Regards,

Jacques

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

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 11, 2018, 3:24pm UTC](https://discourse.julialang.org/t/plot-problem/11585/4 "2018-06-11T15:24:28Z")

</div>

Manually set `ylims = (ymin,ymax)`

---

<div class="post-metadata">

**Author:** ![jcrbloch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcrbloch/32/4396_2.png) [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Post date:** [June 11, 2018, 3:35pm UTC](https://discourse.julialang.org/t/plot-problem/11585/5 "2018-06-11T15:35:28Z")

</div>

Well yes, one could do this, but if you have many plots of this kind it is not very helpful having to set the limits manually on each individual plot. I already use this as a work around, but I’d rather have a more general solution. I tried to use a top margin, but that will just add white space at the top without resolving the problem.

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [June 11, 2018, 4:19pm UTC](https://discourse.julialang.org/t/plot-problem/11585/6 "2018-06-11T16:19:01Z")

</div>

I do not know of a general solution; what I do in this cases is similar to @ChrisRackauckas advice. To avoid manual setting the limits I use maximum() and a scaling factor, e.g.:

` ylims = (minimum(myData), maximum(myData) * 1.1)`

---

<div class="post-metadata">

**Author:** ![jcrbloch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcrbloch/32/4396_2.png) [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Post date:** [June 11, 2018, 5:21pm UTC](https://discourse.julialang.org/t/plot-problem/11585/7 "2018-06-11T17:21:28Z")

</div>

That is exactly how I had solved it already. But depending on the data, the constant 1.1 may be good or not.

Thanks for reacting to my post anyways. I guess that matplotlib only looks at the value of the data point and disregards the line thickness. This is a problem if the curve does not have its maximum at one of the end points of the plotting interval.

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [June 11, 2018, 6:26pm UTC](https://discourse.julialang.org/t/plot-problem/11585/8 "2018-06-11T18:26:51Z")

</div>

To elaborate, you could use a function like the following;

```julia
function expandlim(dataIn, by=0.05)
    oldMin = minimum(dataIn)
    oldMax = maximum(dataIn)
    delta = oldMax - oldMin
    newMin = oldMin - (delta * by)
    newMax = oldMax + (delta * by)
    return newMin, newMax
end

```

This will add 5% (or anything you set with “by=”) of the data range both to the minimum and maximum. So, to plot you use:

```julia
ylims=expandlim(mydata)

```

For example:

```julia
a=rand(10)
plot(1:10, a, lw=8, ylims=expandlim(a))

```

---

<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:** [June 11, 2018, 7:24pm UTC](https://discourse.julialang.org/t/plot-problem/11585/9 "2018-06-11T19:24:57Z")

</div>

I think the long-term solution is for lims to be expanded automatically for line plots, as they already are for scatter. It’s this bit of code that controls it: [https://github.com/JuliaPlots/Plots.jl/blob/30af3c7f8ad8fb7410c3d4e232698f00f9e7a5d1/src/axes.jl#L428-L442](https://github.com/JuliaPlots/Plots.jl/blob/30af3c7f8ad8fb7410c3d4e232698f00f9e7a5d1/src/axes.jl#L428-L442)

You could push for this happening by giving some good arguments here: [https://github.com/JuliaPlots/Plots.jl/issues/1366](https://github.com/JuliaPlots/Plots.jl/issues/1366)

---

<div class="post-metadata">

**Author:** ![pooria4444](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pooria4444](https://discourse.julialang.org/u/pooria4444)\
**Post date:** [June 12, 2018, 12:39pm UTC](https://discourse.julialang.org/t/plot-problem/11585/10 "2018-06-12T12:39:54Z")

</div>

hello,  
I am using windows form of Julia poro and I wrote a code in your programming software. but when i want to run it, i think there is problem which is → ‘‘WARNING: No working GUI backend found for matplotlib’’ .  
if you can help me, i could send you my code.  
please help me !  
Regards,

---

<div class="post-metadata">

**Author:** ![jcrbloch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcrbloch/32/4396_2.png) [@jcrbloch](https://discourse.julialang.org/u/jcrbloch)\
**Post date:** [June 12, 2018, 12:50pm UTC](https://discourse.julialang.org/t/plot-problem/11585/11 "2018-06-12T12:50:38Z")

</div>

Of course there should be two more lines two load the proper packages:

using Plots

pyplot()

y=[1, 9, 9, 1]

plot!(y)

Sorry for that.

---

<div class="post-metadata">

**Author:** ![pooria4444](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pooria4444](https://discourse.julialang.org/u/pooria4444)\
**Post date:** [June 12, 2018, 4:42pm UTC](https://discourse.julialang.org/t/plot-problem/11585/12 "2018-06-12T16:42:07Z")

</div>

Hello,

thank you for youre help.

I am using windows form of Julia poro and I wrote a code in your programming software.

my code name is → ((‘‘dme\_simulation\_no\_pc\_hist\_match\_upwind\_2D\_appleyard.jl’’)) which this code needs → ((‘‘rel\_perms\_real.jl’’)) to Run.

(i attached them in this e-mail)

This code do not have any problem in running but after Running, this warning was shown -\>(( ‘‘WARNING: No working GUI backend found for matplotlib’’ )) ,and no figures were plotted .i think i have a syntax problem in my coding.

Regards,  
pooria
