Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw Visualization Diagram by Python

Shulou Source: shulou.com Published: 2022-06-01 20:01:40 10月22日 Update

This article mainly introduces Python how to draw a visualization map, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Preface

After loading the data:

# time series trend chart import csvimport matplotlibimport numpy as npimport pandas as pdfrom datetime import datetimefrom matplotlibimport pyplot as plt# reads CSV file data file1='D:\\ data. Csv'for file2 in file1: print ('read file:% s'% file2) try: with open (file1) as f: # Open this file And store the result file object in f reader=csv.reader (f) # create a reader reader header_row=next (reader) # return the next line of date,r,VaR= in the file [], [] # declare the storage date List of most values for row in reader: date1=datetime.strptime (row [0]) '% Y _ date1% m _ r.append% d') # convert date data to datetime object date.append (date1) # Storage date r1=float (row [3]) # convert string to numeric r.append (R1) # maximum storage temperature VaR1=float (row [2]) VaR .append (VaR1) # minimum storage temperature except Exception as e: print ('read error' File2,':', e) zhfont1 = matplotlib.font_manager.FontProperties\ (fname= "D:\\ simhei.ttf") # define font matplotlib.rcParams ['axes.unicode_minus'] = False # solve the problem of minus sign'-'display as square # draw image fig=plt.figure (dpi=128,figsize= (8line 5)) plt.plot (date,r,label='r',linewidth=2,c='blue',alpha=1) # Transparency of the color specified by argument alpha 0 means completely transparent 1 (default) completely opaque plt.plot (date,VaR,'--',label='95%VaR',c='m',linewidth=2,alpha=1) plt.fill_between (date,r,VaR,facecolor='blue',alpha=0.1) # fill the chart area with color plt.title ("differential rate of return and its risk time series trend chart, fontproperties=zhfont1,fontsize=12) # chart coordinates set plt.xlabel (" time ", fontproperties=zhfont1,fontsize=10) plt.ylabel (" numerical ", fontproperties=zhfont1 Fontsize=10) plt.tick_params (axis='both',which='major',labelsize=10) plt.legend () # legend shows fig.autofmt_xdate () # draw oblique date label plt.grid (True) # add grid True initials plt.show () # display image Thank you for reading this article carefully. I hope the article "how to draw a visual map for Python" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: File storage data date article time visualization image object series time series temperature trend color minimum line value interest preface area Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Shulou Technology Apple Microsoft