如何更改背景颜色?

时间:2019-06-14 15:23:35

标签: python image 2d background-color

我用以下代码制作了一个长方体。

##defining to plot the cuboid
def cuboid(center, size): 
    """
       Create a data array for cuboid plotting.


       ============= ================================================
       Argument      Description
       ============= ================================================
       center        center of the cuboid, triple
       size          size of the cuboid, triple, (x_length,y_width,z_height)
       :type size: tuple, numpy.array, list
       :param size: size of the cuboid, triple, (x_length,y_width,z_height)
       :type center: tuple, numpy.array, list
       :param center: center of the cuboid, triple, (x,y,z)
   """
    ox, oy, oz = center
    l, w, h = size

   ###Added the fig in order to be able to plot it later
    ax = fig.gca(projection='3d') ##plot the project cuboid

    X=[ox-l/2,ox-l/2,ox-l/2,ox-l/2,ox+l/2,ox+l/2,ox+l/2,ox+l/2] ##corner points of the cuboid
    Y=[oy+w/2,oy-w/2,oy-w/2,oy+w/2,oy+w/2,oy-w/2,oy-w/2,oy+w/2]
    Z=[oz-h/2,oz-h/2,oz+h/2,oz+h/2,oz+h/2,oz+h/2,oz-h/2,oz-h/2]
    ax.scatter(X,Y,Z,c='g',marker='o')  #the plot before rotated

    X_new = ([]) #attaining new corner points after rotated
    Y_new = ([])
    Z_new = ([])

    for i in range(0,8):

        c=np.matrix([[X[i]], ##reading every corner points into matrix format
                    [Y[i]],
                    [Z[i]]])
        u=Rot_Mat*c ##rotating every corner point with the rotation matrix

        X_new = np.append(X_new, u.item(0)) ##appending the corner points with the neighbours
        Y_new = np.append(Y_new, u.item(1))
        Z_new = np.append(Z_new, u.item(2))

        print('\nvertex=\n',c)
        print('\nnew_vertex=\n',u)

        ###Doing a dot product between Rot_Mat and c as earlier but using np.dot as it is necessary with Numpy format, reshaping from(3,1) to (3)
        side[i,:] = np.dot(Rot_Mat, c).reshape(3)

    sides = [[side[0],side[1],side[2],side[3]], ##defining the 6 sides of cuboid
            [side[4],side[5],side[6],side[7]], 
            [side[0],side[1],side[4],side[5]], 
            [side[2],side[3],side[4],side[5]], 
            [side[1],side[2],side[5],side[6]],
            [side[4],side[7],side[0],side[3]]]

    ax.scatter(X_new,Y_new,Z_new,c='darkred',marker='o')  #the plot of corner points after rotated
    ax.scatter(ox,oy,oz,c='crimson',marker='o')  #the previous plot of center 

    ## Add title 
    plt.title('Plot_for_PSM', fontsize=20)

    ##labelling the axes
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    ax.add_collection3d(Poly3DCollection(sides, facecolors='blue', linewidths=1, edgecolors='r', alpha=.25)) ###This draw the plane sides as requred 
    plt.gca().legend(('previous_center','previous_vertices','rotated_vertices','same_center'))




    ax.set_xlim([0,4.5])        
    ax.set_ylim([-.75,.75])
    ax.set_zlim([0,1])

in this我毫不怀疑。 我想在一张图中绘制y&z。该图必须是给定图的其他图作为子图。框架必须包含y&z轴,而x轴不应在那里。长方体的背景框架必须使用不同的颜色,即白黑色或黄色。 因此,您能否提出任何建议或代码提示来解决此问题。

0 个答案:

没有答案