forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Kenneth_Smith

Joined: 18 May 2012
Posts: 499
Location: Hamilton, Lanarkshire, Scotland.

Posted: Tue Aug 10, 2021 11:23 am    Post subject: %pl[native] x/y label positions

While I understand the existing algorithm used to determine the position of the x- and y-axis labels, for general purpose x/y plotting purposes it can result in very poor positioning of the x- and y-axis labels. The code below demonstrates the issue.

While this can be fixed by the programmer via a call back function to draw the labels after the %pl is drawn, a better approach (particularly for those starting to use %pl) would be an additional %pl option, with disables the default mechanism for label positioning and simply places the x-axis label centered on the centre line of the %pl frame and similarly for the y-axis label (similar to excel for example).

This would enhance the overall appeal of %pl for new users, and in my case, allow the simplification of new code.

This is the only remaining issue with the %pl[native] which I seem to run up against on a fairly regular basis.

Perhaps this proposed new option could be considered for a future update?

The direct link to the Clearwin+ enhancements file in the most recent version of Plato was a very good idea. I am finding that very useful.

 Code: module m use clrwin implicit none real*8 :: x(2) = [-1.d0,1.d0],y(2) = [1.d0,-1.d0] contains   integer function gui()   integer i   i = winio@('%mn[Exit]&','Exit')   i = winio@('Press Forward button 40 times observing position of x and y label&')   call winop@('%pl[native,x_array,x_axis="x_data",y_axis="y_data", gridlines,frame,colour=blue,width=2]')   i = winio@('%nl%fn[Consolas]%pl&',500,500,2,x,y)   i = winio@('%sf%^bt[Forward]&',  forward)   i = winio@('%^bt[Backward]&', backward)   i = winio@(' ')   gui = 2   end function gui   integer function forward()     x(2) = x(2) - 0.05d0 + epsilon(1.0)     y(2) = y(2) + 0.1d0  + epsilon(1.0)     call simpleplot_redraw@()     forward = 2   end function forward   integer function backward()     x(2) = x(2) + 0.05d0 + epsilon(1.0)     y(2) = y(2) - 0.1d0  + epsilon(1.0)     call simpleplot_redraw@()     backward = 2   end function backward end module m program main use m, only : gui implicit none integer i i =gui() end program main
PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Wed Aug 11, 2021 7:30 am    Post subject: Ken Thanks for the feedback. I think that this is simply a bug that needs fixing. I have logged it for investigation.
PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Thu Aug 12, 2021 11:24 am    Post subject: Ken I now think that a new option is needed otherwise a change will adversely affect existing code. In future a y-axis caption that starts with a tilde will be centred on the whole y range. The tilde will not be displayed. This will be experimental until you confirm that it works to your satisfaction.
Kenneth_Smith

Joined: 18 May 2012
Posts: 499
Location: Hamilton, Lanarkshire, Scotland.

 Posted: Thu Aug 12, 2021 3:30 pm    Post subject: Thank you Paul, I shall lookout for the next intermediate dlls. Have you included the x_axis? It is also sometimes poorly positioned, as shown in the example code, but not to the same extent as the y_axis. Ken
PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Thu Aug 12, 2021 4:38 pm    Post subject: Ken I will add the same option for the x-axis caption.
DanRRight

Joined: 10 Mar 2008
Posts: 2411
Location: South Pole, Antarctica

Posted: Thu Aug 12, 2021 5:10 pm    Post subject:

I do not think this will break any code because this was just the bug from the beginning. So i suggest not to use tilde. We are all early users of this option, there are just few of us, so we will adjust if needed. Adding tilde is counterintuitive and will break more code in the future

Besides, here is another example of bad placement of caption. It has also other defect you just fixed for the new release so ignore it (i guess, because did not have this new release yet), i just found this older demo as an example. My opinion the placement of caption has to be based on centering along the entire length of the visual axis line (i mean its visual (ix,iy) pixel position). Currently position seems decided by %PL based on data min and data max and if you change y_min manually like i did below the %PL does not see it

 Code: module mod1    use clrwin    parameter (N=5)    real*8 X(N), Y(N)    Data X/1e1, 1e2, 1e3,  1e4, 4e5/    Data Y/2.2, 66, 8333, 1111, 777/    save    contains    INTEGER FUNCTION redraw () !    CALL simpleplot_redraw@()     CALL        plot_redraw@()     redraw = 2     end function redraw    end module !................................    Program bug333    use mod1    i=winio@('%fn[Tahoma]%bf%ts&',2.d0)    CALL winop@("%pl[gridlines]")    call winop@("%pl[axes_pen=2,frame_pen=2,width=2,x_axis='X Axis Title',y_axis='Y Axis Title']")    i=winio@('%ww%pv%pl[native,framed,x_array,scale=log_log,N_GRAPHS=1,y_min=100.]%ff&', 925,700, n, X, Y)    i=winio@('%sf%cn%^bt[Redraw]&', Redraw)    i=winio@('%es')    end
PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Thu Aug 12, 2021 7:05 pm    Post subject: Dan The current default is to place the y-axis caption at the centre of the positive y-axis. For me, and perhaps the authors of many existing programs, this is best. If I change this default then some users will be justifiably aggrieved. Using a tilde seemed to me to be simpler than providing a new option but I am willing to be flexible on this.
DanRRight

Joined: 10 Mar 2008
Posts: 2411
Location: South Pole, Antarctica

Posted: Thu Aug 12, 2021 11:55 pm    Post subject:

This can be used but this placement of caption (in the center of positive part) is very vulnerable to being overwritten by the numbers or by the curve. Here is standard plot which i made out of Ken's example above:

Good that positions and other settings could be adjusted if use Designer Mode, all this can done after plotting without programming, just clicking. I added into the source antialiasing and other things but this actually is not needed because can be done in Designer mode. For all other users who are interested this is the code and how plot captions could look after moving them using Designer mode:

 Code: module m use clrwin implicit none real*8 :: x(2) = [-1.d0,1.d0],y(2) = [1.d0,-1.d0] contains   integer function gui()   integer i   i = winio@('Press Forward button 40 times observing position of x and y label&')   i=winio@('%ww%fn[Tahoma]&')   i =  winio@('%ts%bf&',1.d0) ! font size and bold-face   i =  winio@('%`bg&',rgb@(245,250,255)) ! bluish background for plot   call winop@("%pl[smoothing=4]") ! anti-aliasing for line smoothing   call winop@("%pl[file=zPlotDemo_DesignerMode.set]")      call winop@ ("%pl[axes_pen=2.]")   call winop@('%pl[native,x_array,x_axis="x_data",y_axis="y_data", gridlines,colour=blue,width=2]')   i =  winio@('%nl%pv%pl&',500,500,2,x,y)   i =  winio@('%sf%^bt[Forward]&',  forward)   i =  winio@('%^bt[Backward]&', backward)   i =  winio@('%es')   gui = 2   end function gui   integer function forward()     x(2) = x(2) - 0.05d0 + epsilon(1.0)     y(2) = y(2) + 0.1d0  + epsilon(1.0)     call simpleplot_redraw@()     forward = 2   end function forward   integer function backward()     x(2) = x(2) + 0.05d0 + epsilon(1.0)     y(2) = y(2) - 0.1d0  + epsilon(1.0)     call simpleplot_redraw@()     backward = 2   end function backward end module m program main use m, only : gui implicit none integer i i =gui() end program main

But in most cases more universal is to create the frame like Ken did and place the axis names in the middle of the X and Y entire frames. Here is an example:

Here you can click 40 times or 40000 times the result will look perfect. As another confirmation for that if you click on Ken's example Forward and Backward buttons the current placement in the middle of the positive part will look extremely ugly until it will be absolutely unacceptable aesthetically, permanently moving and at some point completely disappear:

So if frame is used the placement of axis caption ideally has to be in the middle of the frame

Last edited by DanRRight on Fri Aug 13, 2021 7:54 pm; edited 5 times in total
PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Fri Aug 13, 2021 8:08 am    Post subject: Dan In response to your initial comment, I could add a new option [y-axis=caption] that uses a hyphen rather than the existing underscore. This would be instead of using a tilde.
Kenneth_Smith

Joined: 18 May 2012
Posts: 499
Location: Hamilton, Lanarkshire, Scotland.

PaulLaidler

Joined: 21 Feb 2005
Posts: 7068
Location: Salford, UK

 Posted: Fri Aug 13, 2021 10:04 am    Post subject: Ken It would be simpler, both for me to implement and perhaps also for the user, if I add new options [x-axis=name] and [y-axis=name] where the original underscore is replaced by a hyphen. I will implement this approach on an experimental basis then you can test it and report back how you get on.
Kenneth_Smith

Joined: 18 May 2012
Posts: 499
Location: Hamilton, Lanarkshire, Scotland.

 Posted: Fri Aug 13, 2021 11:02 am    Post subject: Paul, That's fine, I think I may be guilty of thinking about this a little too much. Thanks Ken
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1