Menu

#799 Make smooth unwrap respect angle units

Version 5
open
nobody
5
2022-07-13
2022-07-12
Rushi
No

I created a patch to make the smooth unwrap filter respect the set angles setting. With the patch, whenever set angles is set to degrees, the function looks for differences bigger than 180 (instead of pi) and adds or subtracts 360 (instead of 2*pi.

I do not have a build environment to test this but it is straightforward and should work. All I did was to include gadgets.h in interpol.c and then divide all the M_PI values in the unwrap function by ang2rad.

I would really appreciate it if anyone can test this and include it in the next version of gnuplot if we all agree that smooth unwrap should respect the set angles flag.

1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-07-12

    I will look at the patch, but note that it is trivial to convert from degrees to radians on input already:

    #data in radians
    plot 'rad.dat' using 1:2 smooth unwrap
    #data in degrees
    plot 'deg.dat' using 1:($2*pi/180) smooth unwrap
    
     
    • Rushi

      Rushi - 2022-07-12

      Understood, but in my use case, I use set angles degrees not because my data are in degrees, but because I am plotting a function and I want the final plot to be in degrees. In that case, we need to convert from radians to degrees, which messes up smooth unwrap. For example,

      set samples 1000; set logscale x; set xrange [0.01:100]; set yrange [-8:4]; plot [t=0.01:100] '+' using (t):(0-atan2((0+(1*((-1)**((5-1)/2))*((t)**(5)))+(5*((-1)**((3-1)/2))*((t)**(3)))+(1*((-1)**((1-1)/2))*((t)**(1)))),(0+(4*((-1)**((4)/2))*((t)**(4)))+(6*((-1)**((2)/2))*((t)**(2)))+1))) smooth unwrap
      

      generates the plot I want in radians. How do I generate the same plot in degrees?
      I tried

      set samples 1000; set logscale x; set xrange [0.01:100]; set yrange [-8*(180/pi):4*(180/pi)]; plot [t=0.01:100] '+' using (t):((0-atan2((0+(1*((-1)**((5-1)/2))*((t)**(5)))+(5*((-1)**((3-1)/2))*((t)**(3)))+(1*((-1)**((1-1)/2))*((t)**(1)))),(0+(4*((-1)**((4)/2))*((t)**(4)))+(6*((-1)**((2)/2))*((t)**(2)))+1)))*(180/pi)) smooth unwrap
      

      That does not work since it adds and subtracts 2*pi from the points instead of 360.

      Is there a way to scale the plot after smoothing rather than before?

       

      Last edit: Rushi 2022-07-12
      • Karl Ratzsch

        Karl Ratzsch - 2022-07-13

        You can

        set y2tics
        set link y2 via y*180/pi inv y/180*pi
        

        to have radians on the left and degrees on the right, or plot on the (not viewed) y2axis and set up the link the other way round

        #unset y2tics
        set link y2 via y/180*pi inv y*180/pi
        set xrange ...; set y2range ...
        plot f(x) smooth unwrap axes x1y2
        
         
        • Rushi

          Rushi - 2022-07-13

          That works for plotting, but when I set table, the table that gets output contains only the radian values, not the degree values. I tried both

          set table 'plot.table'; set y2tics; set link y2 via y*180/pi inv y/180*pi; set samples 1000; set logscale x; set xrange [0.01:100]; set yrange [-8:4]; set y2range [-8*(180/pi):4*(180/pi)]; plot [t=0.01:100] '+' using (t):(0-atan2((0+(1*((-1)**((5-1)/2))*((t)**(5)))+(5*((-1)**((3-1)/2))*((t)**(3)))+(1*((-1)**((1-1)/2))*((t)**(1)))),(0+(4*((-1)**((4)/2))*((t)**(4)))+(6*((-1)**((2)/2))*((t)**(2)))+1))) smooth unwrap; unset table
          

          and

          unset y2tics; set table 'plot.table'; set link y2 via y/180*pi inv y*180/pi; set samples 1000; set logscale x; set xrange [0.01:100]; set y2range [-8:4]; set yrange [-8*(180/pi):4*(180/pi)]; plot [t=0.01:100] '+' using (t):(0-atan2((0+(1*((-1)**((5-1)/2))*((t)**(5)))+(5*((-1)**((3-1)/2))*((t)**(3)))+(1*((-1)**((1-1)/2))*((t)**(1)))),(0+(4*((-1)**((4)/2))*((t)**(4)))+(6*((-1)**((2)/2))*((t)**(2)))+1))) smooth unwrap axes x1y2; unset table
          

          as per your suggestions. Is there a way to make gnuplot output the y2 values to the table instead of the y values?

          Context:
          I wrote a LaTeX package named bodeplot that uses gnuplot with pgf to generate all the plots. In pgf, gnuplot is used to output a table, which is used with native pgf plotting tools to generate the plots. I could rescale axes in pgf similar to your suggestion, but it would be better if the data gnuplot generates were themselves in degrees when set angles degrees is enabled. This is already the case if I were just plotting a function, but the unwrap filter does not abide by the set angles degrees flag, hence the patch!

           

          Last edit: Rushi 2022-07-13

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.