The following code into first overall redistribution explain:
Import numpy AS NP Import matplotlib.pyplot AS PLT from matplotlib.ticker Import MultipleLocator, FormatStrFormatter DEF minmax_value (List1): MINVALUE = min (List1) MAXVALUE = max (List1) return MINVALUE, MAXVALUE plt.figure (figsize = (16,14 ), dpi = 98 ) xmajorLocator = MultipleLocator (. 1) # x to the main scale tab as 0.2 multiples plt.rcParams [ ' font.sans serif- ' ] = [ ' SimHei ' ] plt.rcParams [ 'axes.unicode_minus'] = False p1 = plt.subplot(121) p2 = plt.subplot(122) #图中展示点的数量 pointcount=5 x=[i for i in range(20)] print(x) y1=[i**2 for i in range(20)] y2=[i*4 for i in range(20)] y3=[i*3+2 for i in range(20)] y4=[i*4 for i in range(20)] for i in range(len(x)-1): if i<pointcount: minx,maxx=minmax_value(x[:pointcount]) minx,maxx=minmax_value(x[:pointcount]) minyA,maxyA=minmax_value(y1[:pointcount]) minyB,maxyB=minmax_value(y2[:pointcount]) maxy1=max(maxyA,maxyB) miny1=min(minyA,minyB) p1.axis([minx,maxx,miny1,maxy1]) p1.grid(True) A,=p1.plot(x[:pointcount],y1[:pointcount],"G- " ) B, = p1.plot (X [: pointcount], Y2 [: pointcount], " B- " ) # Set the position of the main scale label, the label text format p1.xaxis.set_major_locator (xmajorLocator) Legend = p1.legend (Handles = [A, B], Labels = [ " FIG. 1 " , " FIG. 2 " ]) minX, Maxx = minmax_value (X [: pointcount]) minX, Maxx = minmax_value (X [: pointcount]) Minya, maxyA = minmax_value (Y3 [: pointcount]) minyB, maxyB = minmax_value (Y4 [: pointcount]) maxy1= Max (maxyA, maxyB) miny1 = min (Minya, minyB) p2.axis ([minX, Maxx, miny1, maxy1]) p2.grid (True) A, = p2.plot (X [: pointcount], Y3 [ : pointcount], " R- " ) B, = p2.plot (X [: pointcount], Y4 [: pointcount], " Y- " ) # set the position of the main scale tag, label text format p2.xaxis.set_major_locator (xmajorLocator) Legend = p2.legend (Handles = [A, B], Labels = [ " 3 " , " FIG. 4 " ]) elif I> pointcount: minX, Maxx=minmax_value(x[i-pointcount:i]) minx,maxx=minmax_value(x[i-pointcount:i]) minyA,maxyA=minmax_value(y1[i-pointcount:i]) minyB,maxyB=minmax_value(y2[i-pointcount:i]) maxy1=max(maxyA,maxyB) miny1=min(minyA,minyB) p1.axis([minx,maxx,miny1,maxy1]) p1.grid(True) A,=p1.plot(x[i-pointcount:i],y1[i-pointcount:i],"g-") B,=p1.plot(x[i-pointcount:i],y2[i-pointcount:i],"b-") # min (Minya, minyB)Provided the position of the main scale label, the label text format p1.xaxis.set_major_locator (xmajorLocator) Legend = p1.legend (Handles = [A, B], Labels = [ " FIG. 1 " , " FIG. 2 " ]) minX, Maxx minmax_value = (X [I- pointcount: I]) minX, Maxx = minmax_value (X [I- pointcount: I]) Minya, maxyA = minmax_value (Y3 [I- pointcount: I]) minyB, maxyB = minmax_value (Y4 [ I- pointcount: I]) maxy1 = max (maxyA, maxyB) miny1 = p2.grid (True) p2.axis ([minX, Maxx, miny1, maxy1]) A, = p2.plot (X [I-pointcount: I], Y3 [I-pointcount: I], " R- " ) B, = p2.plot (X [I-pointcount: I], Y4 [I- pointcount: I], " Y- " ) # set the position of the main scale label, the label text format p2.xaxis.set_major_locator (xmajorLocator) Legend = p2.legend (Handles = [a, B], labels = [ " 3 " , " FIG. 4 " ]) p1.set_xlabel ( " horizontal axis attribute name " , fontSize = 14 ) p1.set_ylabel ( " longitudinal attribute name " , fontSize = 14 ) P1.set_title(" Theme " , fontSize = 18 ) p2.set_xlabel ( " horizontal axis attribute name " , fontSize = 14 ) p2.set_ylabel ( " vertical axis attribute name " , fontSize = 14 ) p2.set_title ( " Theme II " , 18 is fontSize = ) plt.pause ( 0.3 ) plt.tight_layout (PAD =. 4, w_pad = 4.0, h_pad = 3.0)
Operating results as follows:
1, import library
import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, FormatStrFormatter
2, since the process of drawing a plurality of times using the acquired maximum and minimum, maximum and minimum writing the acquired function, the function can be called directly behind.
def minmax_value(list1): minvalue=min(list1) maxvalue=max(list1) return minvalue,maxvalue
3, (1) create a custom image, and set the length and width, and the drawing object parameter specifies dpi resolution figured; and (2) set the x-axis scale interval; (3) of this drawing font set; (4) in matplotlib, a figure object may comprise a plurality of sub FIG (Axes), using the subplot () fast rendering.
plt.figure(figsize=(16,14),dpi=98)
xmajorLocator = MultipleLocator(1)
plt.rcParams['axes.unicode_minus'] = False
p2 = plt.subplot (122)
4, when an excessive amount of data, the data can not be reached the one-time interpretation of the display data of internal information. This embodiment uses a display wherein a portion of the data, and dynamically updates the image, the same time, the dynamic update of the horizontal axis of ordinate range. The following code first sets the number of points for each impression, and get all the data values in a theme. y acquiring vertical and horizontal coordinates of the current drawing process according x has a value in the range and range, according to the last plotted value of x, the y.
It will first show two static discount on a sub FIG. When dynamic line graph, simply and dynamically update the data in the range of horizontal and vertical coordinates. The overall code has been written, the following will not repeat them.
#图中展示点的数量 pointcount=5 x=[i for i in range(20)] y1=[i**2 for i in range(20)] y2=[i*4 for i in range(20)] minx,maxx=minmax_value(x[:pointcount]) minyA,maxyA=minmax_value(y1[:pointcount]) minyB,maxyB=minmax_value(y2[:pointcount]) maxy1=max(maxyA,maxyB) miny1=min(minyA,minyB) p1.axis([minx,maxx,miny1,maxy1])
p1.grid (True) # grid is provided during the painting process A, = p1.plot (X [: pointcount], Y1 [: pointcount], " G- " ) B, = p1.plot (X [: pointcount ], Y2 [: pointcount], " B- " )
# set the position of the main scale label, the label text format
p1.xaxis.set_major_locator (xmajorLocator)
Legend = p1.legend (Handles = [a, B], labels = [ "FIG. 1", "2"])
The results are as follows: