# Plotly - how to plot Cylinder?

**URL:** <https://community.plotly.com/t/plotly-how-to-plot-cylinder/63925>\
**Category:** Dash Python\
**Created:** [May 10, 2022, 8:39am UTC](https://community.plotly.com/t/plotly-how-to-plot-cylinder/63925 "2022-05-10T08:39:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry2021](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jerry2021](https://community.plotly.com/u/jerry2021)\
**Post date:** [May 10, 2022, 8:39am UTC](https://community.plotly.com/t/plotly-how-to-plot-cylinder/63925/1 "2022-05-10T08:39:48Z")

</div>

> <https://stackoverflow.com/questions/72182976/plotly-how-to-plot-cylinder>

I have a function plotting the cylinder, using matplotlib.

[![](https://i.stack.imgur.com/sfxvg.png) ](https://i.stack.imgur.com/sfxvg.png)  
I am wondering how to do the same using plotly?

below is my matplotlib function of plotting cylinder:

> ```
> #function to plot the cylinder
> def _plotCylinder(self, ax, x, y, z, dx, dy, dz, color='red',mode=2):
> """ Auxiliary function to plot a Cylinder """
> # plot the two circles above and below the cylinder
> p = Circle((x+dx/2,y+dy/2),radius=dx/2,color=color,ec='black')
> p2 = Circle((x+dx/2,y+dy/2),radius=dx/2,color=color,ec='black')
> ax.add_patch(p)
> ax.add_patch(p2)
> art3d.pathpatch_2d_to_3d(p, z=z, zdir="z")
> art3d.pathpatch_2d_to_3d(p2, z=z+dz, zdir="z")
> # plot a circle in the middle of the cylinder
> center_z = np.linspace(0, dz, 15)
> theta = np.linspace(0, 2*np.pi, 15)
> theta_grid, z_grid=np.meshgrid(theta, center_z)
> x_grid = dx / 2 * np.cos(theta_grid) + x + dx / 2
> y_grid = dy / 2 * np.sin(theta_grid) + y + dy / 2
> z_grid = z_grid + z
> ax.plot_surface(x_grid, y_grid, z_grid,shade=False,fc=color,ec='black',alpha=1,color=color)
> x,y,z = item.position
> [w,h,d] = item.getDimension()
> # plot item of cylinder
> self._plotCylinder(axGlob, float(x), float(y), float(z), float(w),float(h),float(d),color=color,mode=2)
> 
> ```

---

<div class="post-metadata">

**Author:** ![jgomes\_eu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jgomes_eu/32/14895_2.png) [@jgomes\_eu](https://community.plotly.com/u/jgomes_eu)\
**Post date:** [May 10, 2022, 9:39am UTC](https://community.plotly.com/t/plotly-how-to-plot-cylinder/63925/2 "2022-05-10T09:39:30Z")

</div>

Hi @jerry2021,  
Please take a look at this answer by @empet**[Basic 3D Cylinders](https://community.plotly.com/t/basic-3d-cylinders/27990/2)**
