您好,登錄后才能下訂單哦!
繪制直線,三角形,正方形
import matplotlib.pyplot as plt def plotLine(): x = [1,2,3,4,5] y = [3,3,3,3,3] plt.figure(figsize=(100,100),dpi=1) plt.plot(x,y,linewidth=150) plt.axis('off') plt.savefig('C:\\Users\\Administrator\\Desktop\\分形圖\\a.jpg',dpi=1) plt.show() plt.close() def plotTriangle(): x = [1,3,1,1] y = [1,1,3,1] plt.figure(figsize=(100,100),dpi=1) plt.plot(x,y,linewidth=150) plt.axis('off') plt.savefig('C:\\Users\\Administrator\\Desktop\\分形圖\\b.jpg',dpi=1) plt.show() plt.close() def plotSquare(): x = [1,3,3,1,1] y = [1,1,3,3,1] plt.figure(figsize=(100,100),dpi=1) plt.plot(x,y,linewidth=150) plt.axis('off') plt.savefig('C:\\Users\\Administrator\\Desktop\\分形圖\\c.jpg',dpi=1) plt.show() plt.close() plotLine() plotTriangle() plotSquare()
from datetime import datetime import os import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from six.moves import xrange data = np.load('data/final37.npy') data_images = data data_images = data_images.reshape(-1,3,61) # data_images = data_images[500:1000,:,:] for i in range(2000): plt.figure(figsize=(100,100),dpi=1) plt.plot(data_images[i][0][0:30],data_images[i][0][30:60],color='blue',linewidth=150) plt.plot(data_images[i][1][0:30],data_images[i][1][30:60],color='red',linewidth=150) plt.plot(data_images[i][2][0:30],data_images[i][2][30:60],color='green',linewidth=150) plt.axis('off') plt.savefig('C:\\Users\\Administrator\\Desktop\\調整分辨率\\原始圖\\resouce%d.jpg' %(i),dpi=1) plt.close() ################################################################################# # 生成隨機分叉圖 # import random # import numpy as np # import operator # import os # import copy # from matplotlib.font_manager import FontProperties # from scipy.interpolate import lagrange # import random # import matplotlib.pyplot as plt # np.set_printoptions(threshold=np.inf) #輸出全部矩陣不帶省略號 # # random.seed(10) # finaldata = [] # for iy in range(100): # #固定一個點,盡量使點固定在0-1正方形的中間 #小數點后16位 # pointx = random.uniform(0.3,0.7) # pointy = random.uniform(0.3,0.7) # ################################################# # #主分支在上方 # a1x = random.uniform(pointx,0.8)#使第二個點盡量不那么大 # a2x = random.uniform(a1x,1) # a3x = random.uniform(a2x,1) # a1y = random.uniform(pointy,0.8) # a2y = random.uniform(a1y,1) # a3y = random.uniform(a2y,1) # ax = [pointx,a1x,a2x,a3x] # ay = [pointy,a1y,a2y,a3y] # # print(ax) # # print(ay) # #對主分支a段進行插值 # #在ax相同索引直接分別插兩個點,最后a段長度由4變成10,既得final_ax # # print(ay) # final_ax = [] # final_ay = [] # for i in range(len(ax)-1): # #round(data,8)小數點保留8位四舍五入 # f = lagrange([round(ax[i],8),round(ax[i+1],8)],[round(ay[i],8),round(ay[i+1],8)]) # insertax = np.linspace(ax[i],ax[i+1],4)#插入2個點,小數點后8位 # insertay = f(insertax) # for axi in insertax: # final_ax.append(axi) # for ayi in insertay: # final_ay.append(ayi) # del final_ax[4] # del final_ax[7] # del final_ay[4] # del final_ay[7] # ################################################# # # #左下分支 # b1x = random.uniform(0.2,pointx)#使第二個點盡量不那么小 # b2x = random.uniform(0,b1x) # b3x = random.uniform(0,b2x) # b1y = random.uniform(0.2,pointy) # b2y = random.uniform(0,b1y) # b3y = random.uniform(0,b2y) # bx = [b3x,b2x,b1x,pointx] # by = [b3y,b2y,b1y,pointy] # #對左下分支b段進行插值 # final_bx = [] # final_by = [] # for i in range(len(bx)-1): # f = lagrange([round(bx[i],8),round(bx[i+1],8)],[round(by[i],8),round(by[i+1],8)]) # insertbx = np.linspace(bx[i],bx[i+1],4) # insertby = f(insertbx) # for bxi in insertbx: # final_bx.append(bxi) # for byi in insertby: # final_by.append(byi) # del final_bx[4] # del final_bx[7] # del final_by[4] # del final_by[7] # # ################################################## # #右下分支 # c1x = random.uniform(pointx,0.8)#使第二個點盡量不那么大 # c2x = random.uniform(c1x,1) # c3x = random.uniform(c2x,1) # c1y = random.uniform(0.2,pointy) # c2y = random.uniform(0,c1y) # c3y = random.uniform(0,c2y) # cx = [pointx,c1x,c2x,c3x] # cy = [pointy,c1y,c2y,c3y] # #對右下分支段進行插值 # final_cx = [] # final_cy = [] # for i in range(len(cx)-1): # f = lagrange([round(cx[i],8),round(cx[i+1],8)],[round(cy[i],8),round(cy[i+1],8)]) # insertcx = np.linspace(cx[i],cx[i+1],4) # insertcy = f(insertcx) # for cxi in insertcx: # final_cx.append(cxi) # for cyi in insertcy: # final_cy.append(cyi) # del final_cx[4] # del final_cx[7] # del final_cy[4] # del final_cy[7] # #################################################### # x = [final_ax,final_bx,final_cx]#三分叉,上為a,左下b,右下c # y = [final_ay,final_by,final_cy] # diameter_a = round(random.uniform(0.2,0.25),8) # diameter_b = round(random.uniform(0.1,0.2),8) # diameter_c = round(random.uniform(0.1,0.2),8) # final_a = []#長度為21前10個x坐標點,后面10個是y坐標點,最后一個是管徑 # for ax in final_ax: # final_a.append(ax) # for ay in final_ay: # final_a.append(ay) # final_a.append(diameter_a) # final_b = [] # for bx in final_bx: # final_b.append(bx) # for by in final_by: # final_b.append(by) # final_b.append(diameter_b) # final_c = [] # for cx in final_cx: # final_c.append(cx) # for cy in final_cy: # final_c.append(cy) # final_c.append(diameter_c) # finalabc = [final_a,final_b,final_c] # finaldata.append(finalabc) # finaldata = np.array(finaldata) # #復制改變a,不改變b # finaldata1 = finaldata.copy() # finaldata2 = finaldata.copy() # finaldata3 = finaldata.copy() # #以定點為中心,進行鏡像處理 # finaldata1[:,:,0:10] = 2 * pointx -finaldata[:,:,0:10] # finaldata2[:,:,10:20] = 2 * pointx -finaldata[:,:,10:20] # finaldata3[:,:,0:20] = 2 * pointx -finaldata[:,:,0:20] # final = np.concatenate((finaldata,finaldata1,finaldata2,finaldata3),axis=0) # np.random.shuffle(final)#隨機打亂數據,若沒有次句,將連續輸出一個方向 # print(final.shape) # # np.save('C:\\Users\\Administrator\\Desktop\\第9周\\80000.npy',final) # ########################################### # # 單個可視化圖像 # for i in range(len(final)): # abc = final[i] # plt.plot(abc[0][0:10],abc[0][10:20],color='blue',linewidth=1.5) # plt.plot(abc[1][0:10],abc[1][10:20],color='red',linewidth=1.5) # plt.plot(abc[2][0:10],abc[2][10:20],color='green',linewidth=1.5) # plt.axis('off') # plt.savefig('C:\\Users\\Administrator\\Desktop\\ttt\\原圖2\\random%d.jpg' %i,dpi=100) # plt.close() ########################################### # 分塊可視化圖像 # data = np.load('C:\\Users\\Administrator\\Desktop\\第8周\\10000.npy') # print(data.shape) # rows,cols = 5,5 # fig,axs = plt.subplots(rows,cols) # cnt = 0 # for i in range(rows): # for j in range(cols): # xy = final[cnt]#第n個分叉圖,有三個分支,每個分支21個數 # for k in range(len(xy)): # x = xy[k][0:10] # y = xy[k][10:20] # if k == 0 : # axs[i,j].plot(x,y,color='blue',linewidth=xy[k][20]*15) # if k == 1: # axs[i,j].plot(x,y,color='red',linewidth=xy[k][20]*15) # if k == 2: # axs[i,j].plot(x,y,color='green',linewidth=xy[k][20]*15) # axs[i,j].axis('off') # cnt +=1 # # plt.savefig('C:\\Users\\Administrator\\Desktop\\第9周\\') # plt.show()
以上這篇Python繪制并保存指定大小圖像的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。