英文:
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):
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)/rt)
beta=1.0
x01(t,beta) = (R + r)cos(tbeta) - dcos((R + r)/rtbeta)
y01(t,beta) = (R + r)sin(tbeta) - dsin((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 "want epicycloid \n with gradient"
R=3.0; r=1.0 ; d=0.5
plot [0:2*pi] '+' u (x01($1,beta)):(y01($1,beta)):(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:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(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
**Result:**
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/5JS6h.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论