Ask Your Question
1

Dashed line in a one variable parametric_plot3d

asked 2023-06-27 00:23:16 +0100

Dan-K gravatar image

Say you have a 3d line parametric plot (or parametric_plot3d with one variable). How can you stile the resulting plotted line in a dashed style?

Checked out the documentation and I noticed parametric_plot3d has an option for border_style. However it looks like this has no affect when the area is zero.

There appears to be linestyle available to 2d plots but this has no effect in 3d plots whether specified directly or in border_style.

I also tried giving the colour a colourmap via colormaps.autumn but I get an error:

TypeError: unable to simplify to float approximation

Example

Below is the specific example I'm trying to dash. It is the second parametric_plot3d with the comments:

var(['x', 'y', 'z', 'u', 'v', 'r', 'theta'])

angle = 30 * pi / 180

radius = tan(angle)*z

show(
    parametric_plot3d(
        (
            r*cos(theta),
            r*sin(theta),
            r/tan(30 * pi / 180)
        ),
        (r, 0, radius(z = 1)),
        (theta, 0, 2*pi),
        opacity = 0.5
    )
    + point3d((radius(z = 0.5), 0, 0.5), color = 'red')
    + parametric_plot3d(
        (
            radius(z = 0.5)*cos(theta),
            radius(z = 0.5)*sin(theta),
            0.5
        ),
        (theta, 0, 2*pi),
        # color = 'red', # Produces a solid red line
        # color = (theta, colormaps.autumn) # Throws an error
        # linestyle = '--', # Does not work
        # boundary_style = {  # Does not work
        #   'thickness': 5,
        #   'linestyle': '--',
        #   'color': 'red'
        # }
    )
)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2023-06-27 09:20:07 +0100

achrzesz gravatar image

updated 2023-06-27 11:58:33 +0100

One can use some workarounds

var('x y z u v r theta')
angle = pi/6
radius = tan(angle)*z
p=parametric_plot3d((r*cos(theta),
                   r*sin(theta),
                   r/tan(angle)),
                   (r, 0, radius(z = 1)),
                   (theta, 0, 2*pi),opacity = 0.3,color='lightgray')
p += point3d((radius(z = 0.5), 0, 0.5), color = 'red',size=11)
p += point3d([(radius(z = 0.5)*cos(theta),
               radius(z = 0.5)*sin(theta),
               0.5) for theta in srange(0,2*pi,0.2)],
                    color='blue')
p.show(frame=False)

You can also add a configurable continuous line

p += line3d([(radius(z = 0.5)*cos(theta),
               radius(z = 0.5)*sin(theta),
               0.5) for theta in srange(0,2*pi,0.2)],
                    color='blue',radius=0.005)
edit flag offensive delete link more

Comments

Thanks for your answer! The first one works pretty well. Not the best looking but the best I've seen so far, thank you! The second example shows a solid circle with one small gap in it for me though.

Dan-K gravatar imageDan-K ( 2023-06-29 00:56:49 +0100 )edit

The gap in solid circle is my fault, one can use for example srange(0,2*pi+0.2,0.2).

In matplotlib linestyle='--' works fine in 3d

import numpy as np
import matplotlib.pyplot as plt
ax = plt.figure().add_subplot(projection='3d')
theta = np.linspace(0, 2* np.pi, 100)
z = np.ones(100)*0.5
r = 0.5
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.set_axis_off()
ax.plot(x, y, z, linestyle='--')
plt.show()
achrzesz gravatar imageachrzesz ( 2023-06-29 10:17:38 +0100 )edit
1

answered 2023-06-27 17:47:00 +0100

slelievre gravatar image

The naming is maybe a bit misleading but

  • parametric_plot is for 2d or 3d parametric arcs or curves
  • parametric_plot3d is for 3d parametric surfaces
edit flag offensive delete link more

Comments

Thanks for your answer! Yes I am aware of the difference between parametric_plot and parametric_plot3d, or at least I think I am. According to the documentation when 3 functions are used in parametric_plot, it behaves the same as parametric_plot3d. I gave it a try anyway but unfortunately, linestyle = '--' has no effect with parametric_plot.

Dan-K gravatar imageDan-K ( 2023-06-29 01:01:51 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-06-27 00:23:16 +0100

Seen: 284 times

Last updated: Jun 27 '23