Office automation 19- to draw dynamic bar graph

First we look at the data:

After the results of the draw are:

Attach Code:

Import matplotlib.pyplot AS PLT
 Import PANDAS AS PD
 Import ImageIO 

plt.rcParams [ ' font.sans serif- ' ] = [ ' SimHei ' ]   # for normal display Chinese label 
plt.rcParams [ ' axes.unicode_minus ' ] = False   # negative for normal display 


DF = pd.read_excel (R & lt ' F.: \ for the computer \ PYwork \ OA \ OA \ office automation source portion _w3cschool.cn \ Chapter: PTT automated processing \ 8.Python generated FIG move data \ cities and counties in China for nearly 20 years the number of data * .xls ' ) 
df.head () # See data 
df.iloc [:,. 1] .plot.barh (Alpha = 0.5, Color = " Red " )# Draw a diagram See 

Images = []
 for I in Range (len (df.columns) -1, -1, -1): # reverse 
    IF I == 0:
         BREAK 
    tmp_df = df.iloc [:, I] 
    title = tmp_df.name
     Print ( " read data {} " .format (title)) 
    tmp_df.plot.barh (XLIM , title = = (0,3000 could) " {} is the number of cities and counties Chinese province " .format ( title), Alpha = 0.5, Color = ' Red ' )
     # between the alpha 0-1, transparency control 
    plt.savefig ( " tmp.png" ) 
    Plt.close ( ' All ' ) 
    IM = imageio.imread ( " tmp.png " ) 
    images.append (IM) 

imageio.mimsave (r ' C: \ the Users \ 17360 \ Desktop \ the Test \ past 20 years China province counties number of data .gif ' , Images, ' GIF ' , DURATION = round (0.5,2 ))
 # support only png format imageio library generated gif format.

Comments and questions are welcome oh ~ ^ _ ^

 

Guess you like

Origin www.cnblogs.com/lizitingxue/p/12629176.html