Skip to content

Commit

Permalink
add plots of x and y to trignometric_plant
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroppeter committed Aug 2, 2022
1 parent 8e9c51e commit 551ddfc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
30 changes: 27 additions & 3 deletions drafts/trigonometric_plant.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1>A plane curve that looks like a plant</h1>
t = linspace(<span class="hljs-number">0.0</span>, <span class="hljs-number">39.0</span>*<span class="hljs-type">Pi</span>*<span class="hljs-number">0.5</span>, <span class="hljs-number">1000</span>)
x = t.map(t =&gt; t*cos(t)^<span class="hljs-number">3</span>)
y = t.map(t =&gt; <span class="hljs-number">9.0</span>*t*sqrt(abs(cos(t))) + t*sin(<span class="hljs-number">0.2</span>*t)*cos(<span class="hljs-number">4.0</span>*t))
df = toDf(x, y)
df = toDf(t, x, y)
ggplot(df, aes(<span class="hljs-string">&quot;x&quot;</span>, <span class="hljs-string">&quot;y&quot;</span>)) + geom_line(color=<span class="hljs-string">&quot;green&quot;</span>) + theme_void() + ggsave(<span class="hljs-string">&quot;trigonometric_plant.png&quot;</span>)</code></pre>
<figure>
<img src="..\trigonometric_plant.png" alt="">
Expand All @@ -65,6 +65,17 @@ <h1>A plane curve that looks like a plant</h1>
<li>I am using <code>theme_void</code> to remove axis and grey grid (not sure how to remove just the grey grid without removing axis)</li>
<li>see below in source code comments addressing issues when running on windows</li>
</ul>
<p>It is nice also to see how <code>x</code> and <code>y</code> look like:</p>
<pre><code class="nim hljs">ggplot(df, aes(<span class="hljs-string">&quot;t&quot;</span>, <span class="hljs-string">&quot;x&quot;</span>)) + xlab(<span class="hljs-string">&quot;t&quot;</span>) + ylab(<span class="hljs-string">&quot;x&quot;</span>) + geom_line() + ggsave(<span class="hljs-string">&quot;trigonometric_plant_x.png&quot;</span>)</code></pre>
<figure>
<img src="..\trigonometric_plant_x.png" alt="">
<figcaption></figcaption>
</figure>
<pre><code class="nim hljs">ggplot(df, aes(<span class="hljs-string">&quot;t&quot;</span>, <span class="hljs-string">&quot;y&quot;</span>)) + xlab(<span class="hljs-string">&quot;t&quot;</span>) + ylab(<span class="hljs-string">&quot;y&quot;</span>) + geom_line() + ggsave(<span class="hljs-string">&quot;trigonometric_plant_y.png&quot;</span>)</code></pre>
<figure>
<img src="..\trigonometric_plant_y.png" alt="">
<figcaption></figcaption>
</figure>
</main>
<footer>
<hr>
Expand All @@ -75,7 +86,7 @@ <h1>A plane curve that looks like a plant</h1>
</div>
</footer>
<section id="source">
<pre><code class="nim hljs"><span class="hljs-keyword">import</span> nimib
<pre><code class="nim hljs"><span class="hljs-keyword">import</span> nimib, strformat

nbInit
nbText: <span class="hljs-string">&quot;&quot;&quot;# A plane curve that looks like a plant
Expand All @@ -87,7 +98,7 @@ <h1>A plane curve that looks like a plant</h1>
t = linspace(<span class="hljs-number">0.0</span>, <span class="hljs-number">39.0</span>*<span class="hljs-type">Pi</span>*<span class="hljs-number">0.5</span>, <span class="hljs-number">1000</span>)
x = t.map(t =&gt; t*cos(t)^<span class="hljs-number">3</span>)
y = t.map(t =&gt; <span class="hljs-number">9.0</span>*t*sqrt(abs(cos(t))) + t*sin(<span class="hljs-number">0.2</span>*t)*cos(<span class="hljs-number">4.0</span>*t))
df = toDf(x, y)
df = toDf(t, x, y)
ggplot(df, aes(<span class="hljs-string">&quot;x&quot;</span>, <span class="hljs-string">&quot;y&quot;</span>)) + geom_line(color=<span class="hljs-string">&quot;green&quot;</span>) + theme_void() + ggsave(<span class="hljs-string">&quot;trigonometric_plant.png&quot;</span>)
nbClearOutput <span class="hljs-comment"># to remove output from ggplotnim when saving the png</span>
nbImage(<span class="hljs-string">&quot;trigonometric_plant.png&quot;</span>)
Expand All @@ -103,7 +114,20 @@ <h1>A plane curve that looks like a plant</h1>
- `color` goes in `geom_line` and not in `aes` call (oddly enough if I put `color=&quot;green&quot;` in `aes` it will plot with a reddish color)
- I am using `theme_void` to remove axis and grey grid (not sure how to remove just the grey grid without removing axis)
- see below in source code comments addressing issues when running on windows

It is nice also to see how `x` and `y` look like:
&quot;&quot;&quot;</span>

nbCode:
ggplot(df, aes(<span class="hljs-string">&quot;t&quot;</span>, <span class="hljs-string">&quot;x&quot;</span>)) + xlab(<span class="hljs-string">&quot;t&quot;</span>) + ylab(<span class="hljs-string">&quot;x&quot;</span>) + geom_line() + ggsave(<span class="hljs-string">&quot;trigonometric_plant_x.png&quot;</span>)
nbClearOutput
nbImage(<span class="hljs-string">&quot;trigonometric_plant_x.png&quot;</span>)

nbCode:
ggplot(df, aes(<span class="hljs-string">&quot;t&quot;</span>, <span class="hljs-string">&quot;y&quot;</span>)) + xlab(<span class="hljs-string">&quot;t&quot;</span>) + ylab(<span class="hljs-string">&quot;y&quot;</span>) + geom_line() + ggsave(<span class="hljs-string">&quot;trigonometric_plant_y.png&quot;</span>)
nbClearOutput
nbImage(<span class="hljs-string">&quot;trigonometric_plant_y.png&quot;</span>)

nbSave
<span class="hljs-comment"># for windows:</span>
<span class="hljs-comment"># - use -d:nolapack, see https://github.com/Vindaar/ggplotnim/issues/133</span>
Expand Down
17 changes: 15 additions & 2 deletions drafts/trigonometric_plant.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nimib
import nimib, strformat

nbInit
nbText: """# A plane curve that looks like a plant
Expand All @@ -10,7 +10,7 @@ nbCode:
t = linspace(0.0, 39.0*Pi*0.5, 1000)
x = t.map(t => t*cos(t)^3)
y = t.map(t => 9.0*t*sqrt(abs(cos(t))) + t*sin(0.2*t)*cos(4.0*t))
df = toDf(x, y)
df = toDf(t, x, y)
ggplot(df, aes("x", "y")) + geom_line(color="green") + theme_void() + ggsave("trigonometric_plant.png")
nbClearOutput # to remove output from ggplotnim when saving the png
nbImage("trigonometric_plant.png")
Expand All @@ -26,7 +26,20 @@ nbText: """Note that:
- `color` goes in `geom_line` and not in `aes` call (oddly enough if I put `color="green"` in `aes` it will plot with a reddish color)
- I am using `theme_void` to remove axis and grey grid (not sure how to remove just the grey grid without removing axis)
- see below in source code comments addressing issues when running on windows
It is nice also to see how `x` and `y` look like:
"""

nbCode:
ggplot(df, aes("t", "x")) + xlab("t") + ylab("x") + geom_line() + ggsave("trigonometric_plant_x.png")
nbClearOutput
nbImage("trigonometric_plant_x.png")

nbCode:
ggplot(df, aes("t", "y")) + xlab("t") + ylab("y") + geom_line() + ggsave("trigonometric_plant_y.png")
nbClearOutput
nbImage("trigonometric_plant_y.png")

nbSave
# for windows:
# - use -d:nolapack, see https://github.com/Vindaar/ggplotnim/issues/133
Expand Down
Binary file added trigonometric_plant_x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trigonometric_plant_y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 551ddfc

Please sign in to comment.