Gnuplot:将参数或极坐标函数转换或重写为调色板线颜色

huangapple go评论126阅读模式
英文:

Gnuplot : convert or rewrite parametric or polar functions for the palette linecolor

问题

在gnuplot中,要使参数方程能够使用palette来着色,你可以按照以下方式操作:

首先,确保你已经设置了调色板,以便为参数方程中的数据点分配颜色。在你的代码中,你已经使用了以下设置来定义一个RGB调色板:

set palette model RGB defined (-1 "blue", 0 "black", 1 "red")

接下来,对于每个要绘制的参数方程,你需要在plot命令中使用lc palette来指定颜色。在你的代码中,你已经使用了以下代码来为x01(t, beta)y01(t, beta)的数据点着色:

plot [0:2*pi] '+' u (r_x($1)):(r_y($1)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette

这个lc palette选项告诉gnuplot使用调色板来为线的颜色着色,同时使用zValueForGradient($1, beta)的值来确定颜色。

所以,确保在你的plot命令中使用lc palette选项,并为每个数据点提供一个值,以便根据调色板为线条着色。这应该使你的参数方程根据palette正确定色。

英文:

What are the rules to formulate either polar or parametric equations in gnuplot such that the palette linecolor can be used?

This post explains the plotting of some parametric equations I am interested in, and I would like to rewrite that plot using the palette ability of gnuplot as described here. I read this post which shows how this might be possible, so my long-winded attempt to get anything close is below - before a brief note: I retained the beta parameter only to get the new plot to work before I understand it - i.e. there is no "beta" parameter I am interested in per se, and I see there is a "convert polar to cartesian" in the code, though I do not grasp how it is being used:

### parametric plot
reset session

x00(t) = (R + r)*cos(t) - d*cos((R + r)/r*t)
y00(t) = (R + r)*sin(t) - d*sin((R + r)/r*t)
#
beta=1.0
x01(t,beta) = (R + r)*cos(t*beta) - d*cos((R + r)/r*t*beta)
y01(t,beta) = (R + r)*sin(t*beta) - d*sin((R + r)/r*t*beta)
#
zValueForGradient(t,beta)= cos(t*beta)
#
# convert polar to cartesian
r_x(t)=x01(t,beta)*cos(t)
r_y(t)=y01(t,beta)*sin(t)
# #
set palette model RGB defined (-1 "blue", 0 "black", 1 "red")
#
set parametric
set size ratio -1
set grid x,y

set multiplot layout 2,2

    # epicycloid:
    set title "want epicycloid \n with gradient"
    R=3.0; r=1.0  ; d=0.5
    plot [0:2*pi] '+' u (r_x($1)):(r_y($1)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette

    # hypotrochoid:
    set title "want hypotrochoid \n with gradient"
    R=5.0;  r=-3.0;  d=5.0
    plot [0:3*pi] '+' u (r_x($1)):(r_y($1)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette


    # epicycloid:
    set title "true epicycloid"
    R=3.0; r=1.0  ; d=0.5
    set xrange[-6:6]
    set yrange[-6:6]
    set trange[0:2*pi]
    plot x00(t),y00(t) w l t '' lw 2 lc "red"

    # hypotrochoid:
    set title "true hypotrochoid"
    R=5.0;  r=-3.0;  d=5.0
    set xrange[-8:8]
    set yrange[-8:8]
    set trange[0:6*pi]
    plot x00(t),y00(t) w l t '' lw 2 lc "blue"


unset multiplot
### end of script

the plot looks like this (wxt 0 enhanced terminal):
Gnuplot:将参数或极坐标函数转换或重写为调色板线颜色

The attempted plots - with no resemblance of epicycloids or hypotrochoids - are on the top row, the plots of the original functions from this plot are on the bottom row. One can clearly see the functions (x01, y01, r_x, r_y in the script) are is getting colored according to the z palette (zValueForGradient(t,beta)). Seems close, but clearly as well, I do not understand how to apply this to functions as described in the source post. It is unclear to me how to treat these functions, or to use the approach in this to get the intended effect.

To reiterate : how should a parametric function be treated in gnuplot so that it will be colored according to palette, but also preserve the nature of function itself?

答案1

得分: 1

I am not sure whether I fully understood your question.
Why do you want to convert x01(t,beta) and y01(t,beta) into cartesian coordinates? They are already in cartesian coordinates. Simply use them directly, e.g. like:


plot [0:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))```

Alternatively, do you maybe want to have a polar plot graph?

<details>
<summary>英文:</summary>

I am not sure whether I fully understood your question.
Why do you want to convert `x01(t,beta)` and `y01(t,beta)` into cartesian coordinates? They are already in cartesian coordinates. Simply use them directly, e.g. like:

plot [0:2*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))

plot [0:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))


Alternatively, do you maybe want to have a polar plot graph?

**Script:**

parametric plot

reset session

x00(t) = (R + r)cos(t) - dcos((R + r)/rt)
y00(t) = (R + r)sin(t) - dsin((R + r)/r
t)

beta=1.0
x01(t,beta) = (R + r)cos(tbeta) - dcos((R + r)/rtbeta)
y01(t,beta) = (R + r)sin(tbeta) - d
sin((R + r)/rtbeta)

zValueForGradient(t,beta)= cos(t*beta)

convert polar to cartesian

r_x(t)=x01(t,beta)*cos(t)
r_y(t)=y01(t,beta)*sin(t)

set palette model RGB defined (-1 "blue", 0 "black", 1 "red")

set parametric
set size ratio -1
set grid x,y

set multiplot layout 2,2

# epicycloid:
set title &quot;want epicycloid \n with gradient&quot;
R=3.0; r=1.0  ; d=0.5
plot [0:2*pi] &#39;+&#39; u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta)) t &#39;&#39; w l lw 2 lc palette

# hypotrochoid:
set title &quot;want hypotrochoid \n with gradient&quot;
R=5.0;  r=-3.0;  d=5.0
plot [0:6*pi] &#39;+&#39; u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta)) t &#39;&#39; w l lw 2 lc palette


# epicycloid:
set title &quot;true epicycloid&quot;
R=3.0; r=1.0  ; d=0.5
set xrange[-6:6]
set yrange[-6:6]
set trange[0:2*pi]
plot x00(t),y00(t) w l t &#39;&#39; lw 2 lc &quot;red&quot;

# hypotrochoid:
set title &quot;true hypotrochoid&quot;
R=5.0;  r=-3.0;  d=5.0
set xrange[-8:8]
set yrange[-8:8]
set trange[0:6*pi]
plot x00(t),y00(t) w l t &#39;&#39; lw 2 lc &quot;blue&quot;

unset multiplot

end of script


**Result:**

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/5JS6h.png

</details>



huangapple
  • 本文由 发表于 2023年3月21日 01:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793577-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定