Plot problem

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)

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.

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 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

1 Like

Manually set ylims = (ymin,ymax)

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.

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)

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.

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

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:

ylims=expandlim(mydata)

For example:

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

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

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

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,

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.

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