Python Forum
How to draw rectangles in pyplot?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to draw rectangles in pyplot?
#4
You need to be sure about points that forms a rectangle. Look at the simplest example below:

from mpl_toolkits.mplot3d import Axes3D                                                                                                                                                                                                                                                                                     
import numpy as np                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                            
from mpl_toolkits.mplot3d import Axes3D                                                                                                                                                                                                                                                                                     
from mpl_toolkits.mplot3d.art3d import Poly3DCollection                                                                                                                                                                                                                                                                     
import matplotlib.pyplot as plt                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                            
fig = plt.figure()                                                                                                                                                                                                                                                                                                          
ax = fig.add_subplot(111, projection='3d')                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                            
rects  = [[[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 1, 0 ], [0, 0, 0]]]                                                                                                                                                                                                                                                               
# Each rectangle is presented as a set of points
# array rects consist of rectangles
                                                                                                                                                                                                                                                                                                                            
ax.add_collection3d(Poly3DCollection(rects))                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                            
vv = np.array(rects)                                                                                                                                                                                                                                                                                                        
ax.scatter(vv[0][:, 0], vv[0][:, 1], vv[0][:, 2], color='r')
plt.show()
Reply


Messages In This Thread
How to draw rectangles in pyplot? - by SuchtyTV - Jul-08-2019, 11:15 AM
RE: How to draw rectangles in pyplot? - by SuchtyTV - Jul-10-2019, 07:25 AM
RE: How to draw rectangles in pyplot? - by SuchtyTV - Jul-14-2019, 09:53 AM
RE: How to draw rectangles in pyplot? - by scidam - Jul-14-2019, 10:07 AM
RE: How to draw rectangles in pyplot? - by SuchtyTV - Jul-14-2019, 02:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add multiple vertical rectangles to a chart in plotly? devansing 2 1,244 Jun-20-2023, 07:55 AM
Last Post: snippsat
  matplotlib.pyplot issue lonaveia 2 2,379 Jul-28-2020, 02:40 PM
Last Post: hussainmujtaba
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 2,224 Mar-28-2020, 08:27 AM
Last Post: j.crater
  zooming in pyplot window SchroedingersLion 0 2,218 Aug-02-2019, 02:59 PM
Last Post: SchroedingersLion
  How to arrange the four pictures of a matplotlib.pyplot? vokoyo 0 2,792 Apr-04-2019, 10:58 PM
Last Post: vokoyo
  matplotlib pyplot ginput issue MLiljeroth 0 3,565 Oct-12-2018, 07:12 AM
Last Post: MLiljeroth
  Problem with Matplotlib.pyplot LTMP 1 2,871 Aug-21-2018, 04:50 AM
Last Post: ichabod801
  Different templates for different rectangles python Akhou 0 1,954 May-03-2018, 01:57 PM
Last Post: Akhou

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020