# Makie can't plot sin(1/x) : \`Makie.convert\_arguments\`

**URL:** https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272
**Category:** General Usage
**Tags:** makie
**Created:** [July 15, 2022, 2:28pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272 "2022-07-15T14:28:13Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [July 15, 2022, 2:28pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/1 "2022-07-15T14:28:13Z")

</div>

Hi all,

I try to plot sin(1/x) by using Makie(CairoMakie)  
[https://makie.juliaplots.org/stable/tutorials/basic-tutorial/](https://makie.juliaplots.org/stable/tutorials/basic-tutorial/)

```julia
using CairoMakie

x = LinRange(0, 10, 100)
y = sin.(1/x)

fig = Figure()
lines(fig[1, 1], x, y, color = :red)
lines(fig[1, 2], x, y, color = :blue)
lines(fig[2, 1:2], x, y, color = :green)

fig

```

There are errors when I do the code above ( I don’t really understand how to convert the arguments), is it impossible to plot sin(1/x) for Makie?

**`Makie.convert_arguments` for the plot type Lines{Tuple{LinRange{Float64, Int64}, LinearAlgebra.Transpose{Float64, Vector{Float64}}}} and its conversion trait PointBased() was unsuccessful.**

**The signature that could not be converted was:**  
**::Vector{Float32}, ::Matrix{Float32}**

**Makie needs to convert all plot input arguments to types that can be consumed by the backends (typically Arrays with Float32 elements).**  
**You can define a method for `Makie.convert_arguments` (a type recipe) for these types or their supertypes to make this set of arguments convertible (See [http://makie.juliaplots.org/stable/recipes.html](http://makie.juliaplots.org/stable/recipes.html)).**

**Alternatively, you can define `Makie.convert_single_argument` for single arguments which have types that are unknown to Makie but which can be converted to known types and fed back to the conversion pipeline.**

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [July 15, 2022, 3:37pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/2 "2022-07-15T15:37:57Z")

</div>

Maybe do `1./x`

---

<div class="post-metadata">

### Author: ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)
#### Post date: [July 15, 2022, 4:32pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/3 "2022-07-15T16:32:28Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> ```julia
> x = LinRange(0, 10, 100)
> y = sin.(1/x)
> 
> ```

As @jules mentioned you need to do `1 ./ x` (note the space) to broadcast the division. `1/x` is doing matrix right division (see the docs).

You probably also don’t want to include `x=0` in your range since `sin(Inf)` is not defined.

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [July 15, 2022, 10:13pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/4 "2022-07-15T22:13:18Z")

</div>

@isaacsas @jules

this is the code, I still can’t plot sin (1/x):

```julia
using CairoMakie, ColorSchemes, Colors
include("/home/browni/LasthrimProjection/makieTheme4.jl") # don't forget to include the theme.

# Generates noise
using Random
Random.seed!(123)
x = -30:0.05:30
# The function
y = sin.(1 ./x)
n=15
y[1:n] = y[1:n] .+ 0.02*randn(n);

fig = Figure(resolution = (600, 400))
ax1 = Axis(fig, xlabel = "x", ylabel = "f(x)",
    xgridvisible = false, 
    ygridvisible = false)
ax2 = Axis(fig, bbox = BBox(140, 260, 260, 350),
    xticklabelsize = 12, yticklabelsize = 12,showgrid=false,
  #title = "inset at (100, 300, 100, 200)"
)
line1 = lines!(ax1, x, y, color = :red)
# inset
lines!(ax2, x, y, color = :red)
limits!(ax2, -3.1,-1.9,-0.05,0.05)
ax2.yticks = [-0.05,0,0.05]
ax2.xticks = [-3,-2.5,-2]
leg = Legend(fig, [line1], ["f(x)"], halign = :right, valign = :top)

fig[1, 1] = ax1
fig[1, 1] = leg

save("./FigInset1.png", fig, px_per_unit = 1)

fig

```

This is the source:  
[https://nbviewer.org/github/lazarusA/MakieNotebooks/blob/main/Makie\_inset.ipynb](https://nbviewer.org/github/lazarusA/MakieNotebooks/blob/main/Makie_inset.ipynb)

Is there any other package to plot an inset? A zoom in at certain x axis for Plotly? or GR? or other package?

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [July 15, 2022, 10:20pm UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/5 "2022-07-15T22:20:58Z")

</div>

This is working fine:

```julia
using CairoMakie

x = LinRange(-3, 3, 2050)
y = sin.(1 ./x)

fig = Figure()
lines(fig[1, 1], x, y, color = :red)
lines(fig[1, 2], x, y, color = :blue)
lines(fig[2, 1:2], x, y, color = :green)

fig

```

or

```julia
using CairoMakie

x = LinRange(-0.1, 1, 250)
y = sin.(1 ./x)

x1 = LinRange(-1, 0.1, 250)
y1 = sin.(1 ./x)

x2 = LinRange(-30, 3, 250)
y2 = sin.(1 ./x)

fig = Figure()
lines(fig[1, 1], x, y, color = :red)
lines(fig[1, 2], x1, y1, color = :blue)
lines(fig[2, 1:2], x2, y2, color = :green)

fig

```

But, how to put the one here, into one up there?

or

How to modify the one here to become an inset?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [July 16, 2022, 6:46am UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/6 "2022-07-16T06:46:37Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> But, how to put the one here, into one up there?

Sorry I don’t understand what you mean.

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [July 16, 2022, 7:33am UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/7 "2022-07-16T07:33:51Z")

</div>

Sorry I should be more clear.

I want to create a zoom in of a plot in certain interval, how? I play around with this code:

```julia
using CairoMakie

x = LinRange(-0.1, 1, 250)
y = sin.(1 ./x)

x1 = LinRange(-1, 0.1, 250)
y1 = sin.(1 ./x)

x2 = LinRange(-30, 3, 250)
y2 = sin.(1 ./x)

fig = Figure()
lines(fig[1, 1], x, y, color = :red)
lines(fig[1, 2], x1, y1, color = :blue)
lines(fig[2, 1:2], x2, y2, color = :green)

fig

```

---

<div class="post-metadata">

### Author: ![braamvandyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/braamvandyk/32/5086_2.png) [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)
#### Post date: [July 16, 2022, 8:02am UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/8 "2022-07-16T08:02:16Z")

</div>

You are reusing x in each line calculating `y`, `y1` and `y2`. I assume you intended to calculate `y1` from `x1` (not `x`) and `y2` from `x2` (also not `x`)

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [July 16, 2022, 8:44am UTC](https://discourse.julialang.org/t/makie-cant-plot-sin-1-x-makie-convert-arguments/84272/9 "2022-07-16T08:44:51Z")

</div>

Wow Thanks a lot!!! must have been a miracle for me that you give me this insight.
