Silverfrost Forums

Welcome to our forums

Can Native PL do this?

20 Mar 2021 7:19 #27298

With the new option of histogram plotting recently added can the new %PL do candles like here?

The link=columns which is doing this seems plots columns from zero, not from arbitrary min value to arbitrary max value. And also can it do that of different colors? Plus can we add the lines on top and bottom of columns? Plus change the column width?

https://i.imgur.com/0YMotoJ.png

https://i.imgur.com/Rlwbvmo.png

20 Mar 2021 10:38 #27299

No Dan, candles in the air takes magic - you obviously didn't attend Hogwarts School ....

20 Mar 2021 10:43 #27300

Dan

%pl does not do this for you but you can do it yourself from a %pl callback function and callback reason 'PLOT_ADJUST'.

You could call get_plot_point@ and then draw your own symbols using draw_filled_rectangleD@ etc..

20 Mar 2021 4:11 #27303

Dan, This is the closest I can get to your requirements without resorting to drawing on the %pl via the call back. I thought it was going to be easy, but I had forgotten that %pl[width] applies to ALL graphs. Ken

winapp
module dan_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: n_candles = 20
real(kind=dp) x(1:n_candles), y_min(1:n_candles), y_low(1:n_candles), y_high(1:n_candles), y_max(1:n_candles)
integer n_graphs
integer,       allocatable :: n_points(:)
real(kind=dp), allocatable :: x_pl(:), y_pl(:)

contains
  integer function create_data()
  integer i
    do i = 1, n_candles
      x(i) = i
      y_max(i)  = 100       * random@()
      y_high(i) = y_max(i)  * random@()
      y_low(i)  = y_high(i) * random@()
      y_min(i)  = y_low(i)  * random@()
      print '(I4,1X,4(F6.3,1X))', i, y_max(i), y_high(i), y_low(i), y_min(i)
    end do
    create_data = 1
  end function create_data

  integer function plot_data()
  integer i, j, counter
  integer iw
  character(len=128) pl_str
    n_graphs = 2*n_candles
    allocate( n_points(1:n_graphs) ) ; n_points = 2
    allocate( x_pl(4*n_candles), y_pl(4*n_candles) )
    counter = 1
    do j = 1, n_candles, 1
      do i = 1, 4, 1
        x_pl(counter) = x(j)
        counter = counter + 1
      end do
    end do
    counter = 1
    do j = 1, n_candles, 1
        y_pl(counter)     = y_min(j)
        y_pl(counter + 1) = y_max(j)
        y_pl(counter + 2) = y_low(j)
        y_pl(counter + 3) = y_high(j)
        counter = counter + 4
    end do
    iw = winio@('%mn[Exit]&','exit')
    iw = winio@('%fn[Consolas]&')
    iw = winio@('%ts%bf&',1.5d0)
    write(pl_str,'('%pl[native,stacked,n_graphs=',I4,']')') n_graphs !  ; print*, pl_str
    call winop@(pl_str)
    call winop@('%pl[x_array, independent, frame, gridlines]')
    do i = 1, n_candles
       call winop@('%pl[link=lines,width=1,colour=blue,pen_style=2]')   !Does not work as written since width applies to all graphs
       call winop@('%pl[link=lines,width=5,colour=red, pen_style=0]')   !Changed pen_style as alternative
    end do
    iw = winio@('%pl&',900,600,n_points,x_pl,y_pl)   
    iw = winio@(' ')
    plot_data = 1
  end function plot_data
end module dan_mod

program main
use dan_mod
implicit none
integer i
  i = create_data()
  i = plot_data()
end program main
20 Mar 2021 4:38 #27304

Or perhaps this ?

winapp
module dan_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: n_candles = 20
real(kind=dp) x(1:n_candles), y_min(1:n_candles), y_low(1:n_candles), y_high(1:n_candles), y_max(1:n_candles)
integer n_graphs
integer,       allocatable :: n_points(:)
real(kind=dp), allocatable :: x_pl(:), y_pl(:)

contains
  integer function create_data()
  integer i
    do i = 1, n_candles
      x(i) = i
      y_max(i)  = 100       * random@()
      y_high(i) = y_max(i)  * random@()
      y_low(i)  = y_high(i) * random@()
      y_min(i)  = y_low(i)  * random@()
      print '(I4,1X,4(F6.3,1X))', i, y_max(i), y_high(i), y_low(i), y_min(i)
    end do
    create_data = 1
  end function create_data

  integer function plot_data()
  integer i, j, counter
  integer iw
  character(len=128) pl_str
    n_graphs = 2*n_candles
    allocate( n_points(1:n_graphs) ) ; n_points = 2
    allocate( x_pl(4*n_candles), y_pl(4*n_candles) )
    counter = 1
    do j = 1, n_candles, 1
      do i = 1, 4, 1
        x_pl(counter) = x(j)
        counter = counter + 1
      end do
    end do
    counter = 1
    do j = 1, n_candles, 1
        y_pl(counter)     = y_min(j)
        y_pl(counter + 1) = y_max(j)
        y_pl(counter + 2) = y_low(j)
        y_pl(counter + 3) = y_high(j)
        counter = counter + 4
    end do
    iw = winio@('%mn[Exit]&','exit')
    iw = winio@('%fn[Consolas]&')
    iw = winio@('%ts%bf&',1.5d0)
    write(pl_str,'('%pl[native,stacked,n_graphs=',I4,']')') n_graphs
    call winop@(pl_str)
    call winop@('%pl[x_array, independent, frame, gridlines, width=4]')
    do i = 1, n_candles
       call winop@('%pl[link=lines,colour=blue,symbol=0]')
       call winop@('%pl[link=lines,colour=red, symbol=6]')
    end do
    iw = winio@('%pl&',900,600,n_points,x_pl,y_pl)   
    iw = winio@(' ')
    plot_data = 1
  end function plot_data
end module dan_mod

program main
use dan_mod
implicit none
integer i
  i = create_data()
  i = plot_data()
end program main
20 Mar 2021 9:25 #27305

Paul,

The examples I posted today in response to Dan’s question “Can Native PL do this?” are based on using the %pl[stacked] option, and representing each candle by two line elements.

This work for n_candles up to 128, where n_graphs in the %pl region reaches 256.

For larger values of n_candles, the code fails as it appears that winop@(‘%pl[colour=red]’) etc can only process the colour/symbol etc instructions for the first 256 graphs.

This is most clearly demonstrated using the second example and setting the integer parameter n_candles = 256, which means n_graphs = 512. When the %pl is drawn, all specified colour and symbol data for the graphs with IDs 257 to 512 is absent.

So although the stacked option has no restriction on n_graphs, calling winop@ is restricted to setting graph parameters for just the first 256 graphs.

CHANGE_PLOT_INT@ etc can be used after the window is formed to change the appearance of the graphs with ids 257 to 512.

Ken

21 Mar 2021 7:16 #27308

Thanks Paul and Ken for suggestions and examples which save my time for experimenting.

22 Mar 2021 8:59 #27316

Ken

At the moment I can't see the restriction in the ClearWin+ code.

Do you have a short sample that illustrates the failure?

22 Mar 2021 1:02 #27319

Paul,

In this example there are 512 graphs, each containing a single point.
When I run the code only the first 256 graphs (i.e. symbols) are displayed.

Although

call winop@('%pl[link=none, colour=red,  symbol=6]'

is called 512 times.

winapp
module paul_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0)
integer, parameter :: ngraph_max = 512
integer :: n_points(1:ngraph_max) = 1
real(kind=dp):: x_pl(ngraph_max), y_pl(ngraph_max)

contains

integer function create_data()
integer i
  do i = 1, ngraph_max, 1
    x_pl(i)=i
    y_pl(i)=i
  end do
create_data = 2
end function create_data

integer function plot_data()
  integer i
  integer iw
  character(len=128) pl_str  

  write(pl_str,'('%pl[native,stacked,n_graphs=',I4,']')') ngraph_max
  call winop@(pl_str)
  call winop@('%pl[x_array, independent, frame, etched, gridlines, width=4]')
  do i = 1, ngraph_max
    call winop@('%pl[link=none, colour=red,  symbol=6]')
    print*, i, x_pl(i), y_pl(i)
  end do
  iw = winio@('%pl&',900,600,n_points,x_pl,y_pl)
  iw = winio@('%ff%cn%bt[OK]&')
  iw = winio@('')
  plot_data = 2
end function plot_data

end module paul_mod

program main
use paul_mod
implicit none
integer i
  i = create_data()
  i = plot_data()
end program main

Here is a screenshot of what I see:

https://www.dropbox.com/s/hj1ov3w6zrfsl2p/pl_stacked.jpg?dl=0

22 Mar 2021 2:51 #27320

Ken

I have fixed this and will send you a new set of DLLs shortly.

23 Mar 2021 12:05 #27323

Paul,

Thanks, I can see that it is fixed with the new DLLs.

And thanks to Dan for the 'candle challenge' which identified the previous restriction.

Please login to reply.