{"id":1444,"date":"2022-04-14T10:29:05","date_gmt":"2022-04-14T17:29:05","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1444"},"modified":"2022-04-14T10:29:05","modified_gmt":"2022-04-14T17:29:05","slug":"210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2022\/04\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2\/","title":{"rendered":"#278 Plot in R"},"content":{"rendered":"<p>#278 Plot in R<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\npng(file=&quot;D:\/projects\/wordpress\/ex278\/ex278a.png&quot;,width=600, height=600)\r\nf.piecewise=function(x){ifelse(x&lt;2,sin(x),x^2)}\r\ncurve(f.piecewise,-3,3,type=&quot;p&quot;,ylab=&quot;A Piecewise Function&quot;)\r\ngrid(NULL,NULL,col=&quot;black&quot;)\r\ndev.off()\r\n\r\npng(file=&quot;D:\/projects\/wordpress\/ex278\/ex278b.png&quot;,width=600, height=600)\r\ncurve(f.piecewise,-3,3,type=&quot;n&quot;,ylab=&quot;A Piecewise Function&quot;)\r\ngrid(NULL,NULL,col=&quot;black&quot;)\r\ncurve(f.piecewise,-3,1.95,add=TRUE,lwd=2)\r\ncurve(f.piecewise,2,3,add=TRUE,lwd=2)\r\npoints(2,sin(2),pch=1,cex=1.5,lwd=2)\r\npoints(2,f.piecewise(2),pch=16,cex=1.5)\r\ndev.off()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278a.png?resize=600%2C600&#038;ssl=1\" alt=\"\" width=\"600\" height=\"600\" class=\"alignnone size-full wp-image-1445\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278a.png 600w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278a-480x480.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 600px, 100vw\" \/><\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278b.png?resize=600%2C600&#038;ssl=1\" alt=\"\" width=\"600\" height=\"600\" class=\"alignnone size-full wp-image-1446\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278b.png 600w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex278b-480x480.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 600px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#278 Plot in R png(file=&quot;D:\/projects\/wordpress\/ex278\/ex278a.png&quot;,width=600, height=600) f.piecewise=function(x){ifelse(x&lt;2,sin(x),x^2)} curve(f.piecewise,-3,3,type=&quot;p&quot;,ylab=&quot;A Piecewise Function&quot;) grid(NULL,NULL,col=&quot;black&quot;) dev.off() png(file=&quot;D:\/projects\/wordpress\/ex278\/ex278b.png&quot;,width=600, height=600) curve(f.piecewise,-3,3,type=&quot;n&quot;,ylab=&quot;A Piecewise Function&quot;) grid(NULL,NULL,col=&quot;black&quot;) curve(f.piecewise,-3,1.95,add=TRUE,lwd=2) curve(f.piecewise,2,3,add=TRUE,lwd=2) points(2,sin(2),pch=1,cex=1.5,lwd=2) points(2,f.piecewise(2),pch=16,cex=1.5) dev.off()<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[],"class_list":["post-1444","post","type-post","status-publish","format-standard","hentry","category-r"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-ni","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1437,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/04\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3\/","url_meta":{"origin":1444,"position":0},"title":"#276 Plot in R","author":"gantovnik","date":"2022-04-14","format":false,"excerpt":"#276 Plot in R [code language=\"python\"] png(file=\"D:\/projects\/wordpress\/ex276\/ex276.png\",width=600, height=350) f=function(x){x^3-3*x^2-9*x+2} curve(f,-4,6,lwd=2,col=\"red\") grid(NULL,NULL,col=\"black\") dev.off() [\/code]","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/gantovnik.com\/bio-tips\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1440,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/04\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2\/","url_meta":{"origin":1444,"position":1},"title":"#277 Plot in R","author":"gantovnik","date":"2022-04-14","format":false,"excerpt":"#277 Plot in R [code language=\"python\"] png(file=\"D:\/projects\/wordpress\/ex277\/ex277.png\",width=600, height=350) f=function(x){x^2*sin(x)} curve(f,-5,5) dev.off() [\/code]","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/gantovnik.com\/bio-tips\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex277.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex277.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex277.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":62,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/piecewise-linear-interpolation\/","url_meta":{"origin":1444,"position":2},"title":"Piecewise linear interpolation","author":"gantovnik","date":"2018-12-24","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex8') os.getcwd() plt.figure(figsize=(10,8)) x = np.linspace(0,1,500) y = np.sqrt(1-x**2) xp = np.linspace(0,1,6) yp = np.sqrt(1-xp**2) xi = np.arange(0.1,1.0,0.2) yi = np.interp(xi,xp,yp) plt.plot(x,y,'b',label='ideal') plt.plot(xp,yp,'or',label='interpolation points') plt.plot(xp,yp,'--r',label='piecewise linear function') plt.plot(xi,yi,'sg',label='interpolated values') plt.legend(loc='best') plt.grid() plt.axis('scaled') plt.axis([0,1.1,0,1.1]) plt.title('Piecewise linear interpolation') plt.savefig(\"example8.png\", dpi=100) plt.show() plt.close()","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example8","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example8.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example8.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example8.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1452,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/05\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2-2-2\/","url_meta":{"origin":1444,"position":3},"title":"#280 TSA data plot using R","author":"gantovnik","date":"2022-05-03","format":false,"excerpt":"Number of passengers at USA Airport TSA checkpoints for 2019, 2020, 2021 and 2022 [code language=\"python\"] install.packages('xml2') install.packages('rvest') install.packages('tidyverse') install.packages('janitor') #install.packages('themeani') #install.packages(\"ggplot2\") #install.packages(\"magrittr\") #install.packages(\"dplyr\") library('xml2') library(rvest) library(tidyverse) library(ggplot2) library(dplyr) library('xml2') library(rvest) library(tidyverse) #read_html(\"https:\/\/www.tsa.gov\/coronavirus\/passenger-throughput?page=0\") -> myurl #html_table(myurl, header = TRUE, fill = TRUE) -> tsa #working directory setwd(\"D:\/projects\/wordpress\/ex280_tsa\") tsa <- read.table(\"data_tsa.txt\",\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/gantovnik.com\/bio-tips\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/05\/tsa_2022_05-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/05\/tsa_2022_05-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/05\/tsa_2022_05-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1226,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1444,"position":4},"title":"#218 Polar plot","author":"gantovnik","date":"2021-11-28","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt r = np.arange(0, 2, 0.01) theta = 2 * np.pi * r fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) ax.plot(theta, r) ax.set_rmax(2) ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line ax.grid(True) ax.set_title(\"A line\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex218.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":73,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/spline-interpolation\/","url_meta":{"origin":1444,"position":5},"title":"Spline interpolation","author":"gantovnik","date":"2018-12-24","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import spline os.chdir('\/home\/vg\/Downloads\/projects\/ex11') os.getcwd() plt.figure(figsize=(10,8)) xp = np.linspace(0,1,6) yp = np.sqrt(1-xp**2) xi = np.linspace(0,1,100) yi = np.interp(xi,xp,yp) ys = spline(xp,yp,xi) plt.plot(xp,yp,'o',label='given points',lw=2) plt.plot(xi,yi,'--',label='piecewise linear',lw=2) plt.plot(xi,ys,'-',label='spline',lw=2) plt.legend(loc='best') plt.grid() plt.xlabel('x') plt.ylabel('y') plt.title(r'Spline interpolation of $y=\\sqrt{1-x^2}$') plt.axis('scaled') plt.axis([0,1.2,0,1.2]) plt.savefig(\"example11.png\", dpi=100) plt.show()\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example11","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example11.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example11.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example11.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=1444"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1444\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}