<script src='https://www.gstatic.com/charts/loader.js'></script> was added in the page head.
xxxxxxxxxx
%%html
<div id='googlechart' style='width:530px; height:580px;'/><script>
google.charts.load('current',{'packages':['corechart']})
google.charts.setOnLoadCallback(drawChart);
var doc=document.getElementById('googlechart');
var n=24,q=.01,m=638; var s2='ϱ = 1 + cos '.concat(n).concat(' θ');
var s1='ϱ = cos '.concat(n).concat(' θ');
function drawChart() {
var xy=Array(2*m).fill(0).map((r,t)=>
[(Math.floor(t/m)+r+Math.cos(n*q*t))*Math.cos(q*t),
(r+Math.cos(n*q*t))*Math.sin(q*t),
(r+Math.floor(t/m)+Math.cos(n*q*t))*Math.sin(q*t)]);
for (var i=1; i<m-1; i++) {xy[m-1+i][1]=NaN; xy[i+1][2]=NaN;}
xy.unshift(['x',s1,s2]);
var data=google.visualization.arrayToDataTable(xy),
options={curveType:'function',legend:{position:'bottom'}};
var chart=new google.visualization.LineChart(doc);
chart.draw(data,options); };
The Python Variant
xxxxxxxxxx
import numpy,pylab; n,m=24,600
T=numpy.linspace(start=0,stop=2*numpy.pi,num=m)
XY=numpy.array([[(numpy.cos(n*T)+r)*numpy.cos(T),
(numpy.cos(n*T)+r)*numpy.sin(T)] for r in range(3)])
XYP=numpy.array([[T,abs(r+numpy.cos(n*T))] for r in range(3)])
fig=pylab.figure(figsize=(5,10)); ax1=fig.add_subplot(211)
ax2=fig.add_subplot(212,projection='polar')
colors=['#ff36ff','#ff3636','#3636ff']
labels=[u'ϱ = cos %sθ'%n,u'ϱ = 1 + cos %sθ'%n,u'ϱ = 2 + cos %dθ'%n]
[ax1.plot(XY[i][0],XY[i][1],color=colors[i],label=labels[i])
for i in range(3)]
[ax2.plot(XYP[i][0],XYP[i][1],color=colors[i],label=labels[i])
for i in range(3)]
lines,labels=ax1.get_legend_handles_labels()
ax1.legend(lines,labels,bbox_to_anchor=(1,1.15),loc=5)
ax1.grid(); ax1.set_xlim(-4,4); ax1.set_ylim(-4,4);
ax1.set_xlabel('x'); ax1.set_ylabel('y'); pylab.show()
No comments:
Post a Comment