Python matplotlib Drawing and dpi correspondence

Source: Internet
Author: User

DPI indicates the size of the drawing area in the plot is not the outer border of the picture

Dpi=1 600x400

dpi=2 1200x800

Dpi=3 1800x1200

........

Dpi=21 (21x600) x (21x400)---> 12600x8400

Example code:

Import TimeImportscipy.signal as SignallImportNumPy as NPImportmatplotlibImportMatplotlib.pyplot as Plty_axis_last=np.linspace (0.0, 0.0, 21120) plt_x=0plt_arr=np.random.rand (1024, 1)defparse_output (Start_freq, Stop_freq,step, Donser_now_lable,donser, Num_now, min_freq):"""Parse data from Soapy_power"""    #Define SizeX_axis = Np.linspace (Start_freq, Stop_freq, round (Stop_freq-start_freq)))  Y_axis= Np.linspace (0.0, 0.0, round (Stop_freq-start_freq)))  #print (len (x_axis))Donser_now_lable=donser_now_lable+Len (x_axis)#Y_axis Deal    GlobalY_axis_last, plt_x, Plt_arr i=0 Temp_lab=0 forNuminchRange (Donser_now_lable+1,len (donser), 1 ):        ifnum>=Len (donser): Y_axis[i]=0 Temp_lab=len (Donser)-donser_now_lableifNum_now==1: Y_axis[i]=Donser[num]Else: Y_axis[i]= (donser[num]*0.65+y_axis_last[i]*0.35) I=i+1ifi==Len (x_axis): BreakY_axis_last=Y_axis time_stop=time.time ()#FFT Change    iftemp_lab!=0:return-1wave_data1=Y_axis[0:len (X_axis)]#print (len (x_axis))WAVE_DATA2 = Wave_data1 *Signall.hann (len (x_axis)) C=np.fft.fft (Wave_data2[0:len (x_axis)) *2/Len (x_axis)#Print (len (c))D=int (Len (c)/2) Y_axis=ABS (C[0:d]) x_axis.resize (d) Min=100Max=0 forIinchRange (0,len (y_axis), 1 ):        ifY_axis[i]>Max:max=Y_axis[i]ify_axis[i]<Min:min=Y_axis[i]#print (max)        #print (min)                    #X_axis y_axis to buffer & update buffer    ifMin_freq isNone:min_freq=Start_freqifStart_freq = =Min_freq:databuffer= {"timestamp": Time_stop,"x": List (x_axis),"y": List (Y_axis)}Else: databuffer["x"].extend (x_axis) databuffer["y"].extend (Y_axis)ifStop_freq >0:#data_storage.update (DataBuffer)        #Self.plt_arr=np.random.rand (1024x768)        #self.plt_x=0        #print (self.plt_x)        ifplt_x==0:plt_arr=Y_axis plt_arr.resize (Len (y_axis),1)            Print(" First time")        Else: Plt_temp=Y_axis plt_temp.resize (Len (y_axis),1) Plt_arr=np.concatenate (plt_arr,plt_temp), Axis=1)            #print (Self.plt_arr)            ifplt_x%1000==0:Print(plt_x)ifplt_x%1000==0:cm=' Hot'Norm= Matplotlib.colors.Normalize (Vmin=min, vmax=max) Map=plt.imshow (plt_arr,interpolation='Nearest', Cmap=cm,norm=norm, origin='Upper') Plt.xticks ([]) plt.yticks ([]) Plt.axis ('off')                #Plt.colorbar (mappable=map,ax=none,shrink=0.5, pad=0)Plt.savefig ("Filename.png", dpi=1320)                     #plt.show ()                Print("-------------------------->")                Print(plt_x) plt_x+=1Temp_str=Str (num_now)returndonser_now_labledefMain (): Num_now=1donser_now_lable=0 Sys_start_freq= 87000000.0#start Fre 87MHZSys_stop_freq = 108127168.0#Stop Fre 108MHZStep = 10316#5158 # 2579.0 #Bin size 1KHZ new (108127168-87000000)/8192Bins = 2048#4096 #8192 #21120 # 10560 #sampling number MHZ    #time_s = 1 #? timesStop_freq = Sys_start_freq#InitMin_freq =None plt_x=0#donser=np.fromfile ("C:\\users\\administrator\\desktop\\bins\\123.b_le.bin", dtype=np.int16)Donser=np.fromfile ("C:\\users\\administrator\\desktop\\bins\\1.b_le.bin", Dtype=np.int16, count=629145600)#600M 629145600     while1:        #Time_start = Time.time ()Start_freq =Stop_freqifstart_freq>=Sys_stop_freq: BreakStop_freq= start_freq+Bins#print ("Start:", Start_freq)        #print ("Stop:", Stop_freq)donser_now_lable=parse_output (Start_freq,stop_freq, Step,donser_now_lable,donser, Num_now, min_freq) Num_now=num_now+1ifdonser_now_lable>=Len (donser): Breakif __name__=="__main__": Main ()

On the code read into a binary bin data file part 1.08GB, the data format for the packet-free, small-end mode, 16-bit encoded spectral data dpi=1320, generate a picture named Filename.png

Python matplotlib Drawing and dpi correspondence

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.