# Need help to adjust axis limit of live plot with makie

**URL:** <https://discourse.julialang.org/t/need-help-to-adjust-axis-limit-of-live-plot-with-makie/41638>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [June 17, 2020, 11:53pm UTC](https://discourse.julialang.org/t/need-help-to-adjust-axis-limit-of-live-plot-with-makie/41638 "2020-06-17T23:53:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fringe](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@Fringe](https://discourse.julialang.org/u/Fringe)\
**Post date:** [June 17, 2020, 11:53pm UTC](https://discourse.julialang.org/t/need-help-to-adjust-axis-limit-of-live-plot-with-makie/41638/1 "2020-06-17T23:53:44Z")

</div>

currently, the way i live plot with Julia is i write new data to a file, and anytime that file update i update my plot. probably not the best but it works for me anyhow i want to adjust the range of my plot but the problem is if i manually do so it breaks the live plotting. let me elaborate: when i don’t manually adjust my y-axis range everything updates and progresses on the plot, by this i mean both my y-axis and x-axis do get adjusted as i read new data but when i fix the y-axis range x-axis range stops progressing but it does plot them just won’t update the x-axis anymore

```julia
function work(fin)
    #cheking if my file got updated
    if watch_file(fIn, 10).changed == 1
        plotTime= 2000; # the amount of data shown on screen
        windSec = plotTime; 
        initLeng= plotTime
        readData=0;
        # reading the data
        while (readData == 0)
            try
                readData = readdlm(fIn, ',', Float64)
            catch e
                readData=0;
            end
        end
        # x axis
        xdata=Node([zeros(windSec-1) ; readData[1,1]] ) ;
        xSize = lift(b -> length(b), xdata) ;
        x = lift(a -> to_value(xdata)[max(1, a-initLeng+1):max(a,initLeng)], xSize)

        #Y data1 :
        ydata1=Node([zeros(windSec-1) ; readData[1,2]])
        ySize1= lift(a -> length(a), ydata1)
        y1= lift(a -> to_value(ydata1)[max(1, a-initLeng+1):max(a,initLeng)], ySize1)
        scene = Scene();
        plot1=lines!(scene, x, y1)
        scene=plot1

         #= 
         ######################################################   
         here i tried to do y axis adjustment but it fails so i leave it 
         for now as comment 
        #######################################################
        # 1- i tried to do it this way didn't work
        #plot1=lift(a-> lines!(scene, x, a),y1)
        #ylims!(to_value(plot1),(-1,2))
        
        # 2- I tried to do it this way didn't work either 
        # ylims!(scene,(-1,2))
         =#

        #using abstract ploting if i want to have to data in one windows
        #scene = AbstractPlotting.vbox(to_value(plot1))
        display(scene)
        while true && isopen(scene)
            if watch_file(fIn, 10).changed == 1
                readData = 0
                while (readData==0)
                    try
                         readData = readdlm(fIn, ',', Float64)
                    catch e
                         readData=0;
                    end
                end

                #update the data :
                xdata[] = append!(to_value(xdata), readData[1,1])
                ydata1[] = append!(to_value(ydata1), readData[1,2])

                AbstractPlotting.update_limits!(scene)
                AbstractPlotting.update!(scene)

            end
        end
    end
end

```

in my function, i have block comment where i tried to adjust the y-axis but failed i attached two picture ones where i use ` ylims!()` function and when i don’t and when i don’t use that function it clearly update the x axis but when i do use it stops updating it i have no clue what i am doing wrong but who ever save me from my suffering i would appreciate it. i spent more than 10-15 hours trying to fix this and found no result.

 ![notworking](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b2f76e59966244e83fc35b2718a56477e994bca.png) ![working](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e8bb3f0619a09a2e0ca155c9e2b8c6e497e53f1.png)

---

<div class="post-metadata">

**Author:** ![Fringe](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@Fringe](https://discourse.julialang.org/u/Fringe)\
**Post date:** [June 19, 2020, 12:59am UTC](https://discourse.julialang.org/t/need-help-to-adjust-axis-limit-of-live-plot-with-makie/41638/2 "2020-06-19T00:59:38Z")

</div>

solved it by :

```julia
limits = lift((x,y) -> FRect(to_value(x)[1], minimum(to_value(y1))-2, (to_value(x)[end]-to_value(x)[1])+5, maximum(to_value(y1))+5),x,y1)

plot1=lines!(scene, x, y1,limits=limits)

```

thank you my self 😃

---

<div class="post-metadata">

**Author:** ![David\_A1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/david_a1/32/209666_2.png) [@David\_A1](https://discourse.julialang.org/u/David_A1)\
**Post date:** [June 27, 2024, 2:24pm UTC](https://discourse.julialang.org/t/need-help-to-adjust-axis-limit-of-live-plot-with-makie/41638/3 "2024-06-27T14:24:49Z")

</div>

Thanks
