2016-03-13 8 views
5

साथ भूखंड पर छवियाँ घुमाया मैं वर्तमान में एक साजिश आयत पैच का उपयोग कर पदों की एक अनुक्रम प्रदर्शित करने के लिए का निर्माण किया गया है।ओवरले matplotlib

Plot of sequence

संपादित करें: कोड इस (RLPy पुस्तकालय के बंद का निर्माण) उत्पन्न करने के लिए इस्तेमाल किया -

def visualize_trajectory(self, trajectory=[[0,0,0,0], [0.1,0.1,0,0]]): 
    domain_fig = plt.figure() 

    for i, s in enumerate(trajectory): 
     x, y, speed, heading = s[:4] 
     car_xmin = x - self.REAR_WHEEL_RELATIVE_LOC 
     car_ymin = y - self.CAR_WIDTH/2. 

     car_fig = matplotlib.patches.Rectangle(
      [car_xmin, 
      car_ymin], 
      self.CAR_LENGTH, 
      self.CAR_WIDTH, 
      alpha=(0.8 * i)/len(trajectory)) 
     rotation = Affine2D().rotate_deg_around(
      x, y, heading * 180/np.pi) + plt.gca().transData 
     car_fig.set_transform(rotation) 
     plt.gca().add_patch(car_fig) 

वहाँ छवियों के साथ इन पैच से प्रत्येक ओवरले करने के लिए कोई तरीका है? आदर्श रूप में, वहाँ एक कार छवि के बजाय पदों में से प्रत्येक पर एक आयत होगा।

मैं AnnotationBbox और TransformedBbox के साथ चारों ओर खेला है, लेकिन दोनों जब रोटेशन के साथ काम कर अनम्य होने लगते हैं।

+0

कोड ऊपर संलग्न। – richliaw

उत्तर

2

demo_affine_image matplotlib gallery से एक नज़र डालें। यह एक छवि को घुमाने के लिए कैसे को दर्शाता है।

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.transforms as mtransforms 
import matplotlib.cbook as cbook 

def get_image(): 
    fn = cbook.get_sample_data("necked_tensile_specimen.png") 
    arr = plt.imread(fn) 
    # make background transparent 
    # you won't have to do this if your car image already has a transparent background 
    mask = (arr == (1,1,1,1)).all(axis=-1) 
    arr[mask] = 0 
    return arr 

def imshow_affine(ax, z, *args, **kwargs): 
    im = ax.imshow(z, *args, **kwargs) 
    x1, x2, y1, y2 = im.get_extent() 
    im._image_skew_coordinate = (x2, y1) 
    return im 

N = 7 
x = np.linspace(0, 1, N) 
y = x**1.1 
heading = np.linspace(10, 90, N) 
trajectory = list(zip(x, y, heading)) 
width, height = 0.3, 0.3 
car = get_image() 
fig, ax = plt.subplots() 
for i, t in enumerate(trajectory, start=1): 
    xi, yi, deg = t 
    im = imshow_affine(ax, car, interpolation='none', 
         extent=[0, width, 0, height], clip_on=True, 
         alpha=0.8*i/len(trajectory)) 
    center_x, center_y = width//2, height//2 
    im_trans = (mtransforms.Affine2D() 
       .rotate_deg_around(center_x, center_y, deg) 
       .translate(xi, yi) 
       + ax.transData) 
    im.set_transform(im_trans) 

ax.set_xlim(-0.5, 1.5) 
ax.set_ylim(-0.5, 1.7) 
plt.show() 

enter image description here