Plots and Shape?

I found the following code in this discourse (there seems to be a couple of versions of it):

``````import Plots as plt
ang = range(0, 2π, length = 60)
ellipse(x, y, w, h) = plt.Shape(w*sin.(ang).+x, h*cos.(ang).+y)    # Returns a Shape object
myshapes = [ellipse(x,rand(),rand(),rand()) for x = 1:4]
plt.plot(myshapes)
``````

and I think this worked a few weeks ago. But now it does not work…

The result is the same as the following code (which still works):

``````ang = range(0, 2π, length = 60)
ellipse(x, y, w, h) = w*sin.(ang).+x, h*cos.(ang).+y    # Returns a tuple
myshapes = [ellipse(x,rand(),rand(),rand()) for x = 1:4]
plt.plot(myshapes,st=:shape)
``````

and produces:

Question: Has there been a breaking change in `Plots` so that `Shape` doesn’t work any more? [Or do I do something wrong?]

There were a few changes regarding shapes lately,
such as

does it work on 1.13.2?

1 Like

I don’t understand what’s going on… Let `myshapes` be defined as [just so we know which `myshapes` version I’m talking about]:

``````ang = range(0, 2π, length = 60)
ellipse(x, y, w, h) = plt.Shape(w*sin.(ang).+x, h*cos.(ang).+y)    # Returns a Shape object
myshapes = [ellipse(x,rand(),rand(),rand()) for x = 1:4]
``````
1. I use `Plots v1.15.1`.
2. If I do `plt.plot(myshapes)`, I get an error message. Note: `myshapes` is a vector of `Shape`s.
3. If I instead do the following, then things work:
``````plt.plot()
for s in myshapes
plt.plot!(s)
end
plt.plot!()
``````

To me, this appears to be a bug in how the recipe “unpacks” the vector of `Shape`s???

Or is the recipe changed so that it cannot plot vectors of shapes?

I can confirm that this works on Plots 1.0.0, but not on 1.13.2. Can you open an issue on github? This is a good test example

1 Like

Done.

1 Like

This should be fixed on 1.15.2

1 Like

Seems to work!

Thanks a lot!!