-
Customizing plots
-
Plotting multiple graphs
import matplotlib.pyplot as plt plt.plot(x, y1, 'red') plt.plot(x, y2, 'blue') plt.xlabel('x') plt.title('title') plt.show() # units between 0 and 1 plt.axes([x_figure, y_figure, width, height]) #subplot:nmk:n rows * m columns ,k subplot plt.subplot( n,m ,k) # Use plt.tight_layout() to improve the spacing between subplots plt.tight_layout()
-
Customizing axes
#Controlling axis extent plt.axis((xmin, xmax, ymin, ymax)) plt.xlim((min, max)) plt.ylin((min, max)) #Equal scaling on x, y axes plt.axis('equal')
-
Legends, annotations, and styles
#Wrovide labels for overlaid points and curves #That could be :'upper left' or 'lower center' or 'best' or 'right' plt.legend(___) #Text labels and arrows using annotate() method plt.annotate(text_label, xy=(___),xytext=(___), arrowprops={'color':___}) #Working with plot styles, such as'ggplot' plt.style.use(___)
-
-
Plotting 2D arrays
-
Working with 2D arrays
#meshgrids:假设u是长度为m的向量,v是长度为n的向量,则最终生成的矩阵X和Y的维度都是 nm u = np.linspace(a, b, c) v = np.linespace(num1, num2, num3) X,Y = np.meshgrid(u, v)
-
Visualizing bivariate functions
plt.pcolor(___) plt.colorbar() plt.show() # gray color may plt.pcolor(___, cmap='gray') #Attention plt.pcolor(Z) plt.pcolor(X, Y, Z) # Axes determined by mesh grid arrays X,y #Contour plots plt.contour(___) plt.show() #Filled contour plots plt.contourf(X, Y, Z 30) plt.colorbar() plt.show()
-
Visualizing bivariate distributions
#Histograms in 2D #Common choices : rectangles & hexagons plt.hist2d(x, y, bins=(___,___)) plt.colorbar() plt.hexbin(x, y, gridsize=(___,___)) plt.colorbar()
-
Working with images
#Loading images img = plt.imread(___) plt.imshow(img) plt.axis('off') plt.show() #Reduction to gray-scale image collapsed = img.mean(axis=2) plt.set_cmap('gray') plt.imshow(collapsed, cmap='gray') plt.axis('off') plt.show() #Uneven samples uneven = collapsed[::4, ::2] plt.imshow(uneven) plt.axis('off') plt.show() #Adjusting aspect ration plt.imshow(uneven, aspect=2.0) plt.axis('off') plt.show()
-
-
Statistical plots with Seaborn
-
Visualizing Regressions
#seaborn #hue, col, row: strings #定义数据子集的变量,并在不同的图像子集中绘制 import pandas as pd import matplotlib.pyplot as plt import seaborn as sns tips = sns.load_dataset(___) sns.lmplot(x=___,y=___, data=___, hue=___, palette=___) plt.show() #residplot: similar arguments as lmplot() but more flexible sns.residplot((x=___,y=___, data=___) #sns:http://www.manongjc.com/article/52835.html #https://www.jianshu.com/p/c26bc5ccf604 #https://blog.csdn.net/wuzlun/article/details/80324849
-
Visualizing univariate distributions
#Strip plot sns.stripplot(y=___, data=___) sns.stripplot(x=___,y=___, data=___) #Spreading out strip plot : size=___,jitter=True #Swarm plot sns.swarmplot(x=___,y=___, data=___) #Changing orientation : orient='h' #Violin plot sns.violinplot(x=___,y=___, data=___)Visualizing multivariate distributions
-
Visualizing multivariate distributions
#Joint plots sns.jointplot(x=___,y=___, data=___) #kde: kind='kde', 'scatter', 'reg', 'resid' #Pair plots sns.pairplot(___) #Heat maps sns,heatmap(___)
-
-
Analyzing time series and images
-
Visualizing times series
#make formatted label labels = dates.striftime('%b %d') print (labels) ['Jan 01',...] #xtick plt.xticks(dates, labels, rotation=___)
-
Time series with moving windows
# A 'moving window' refers to a time interval in a time !!!!!!!!!!!!!!待补充
-
Histogram equalization in images
#Image histograms orig = plt.imread(___) pixels = orig.flatten() #flatten a 2D array into a 1D array plt.hist(pixels,___) #Rescaling the image minval, maxval = orig.min(), orig.max() rescaled = (225/(maxval-minval)*(pixels - minval)) plt.imshow(rescaled) plt.axis('off') plt.show() #Image histogram & CDF plt.hist(pixels,___) plt.twinx() #表示共享x轴,添加y轴的坐标轴 plt.hist(pixels, cumulative=True) plt.show() #Equalizing intensity values new_pixels = np.interp(pixels, bins[:-1], orig_cdf*255) #一维线性插值 new = new_pixels.reshape(orig.shape) plt.imshow(new) plt.axis('off') plt.show()
-
Introduction to Data Visualization with Python(datacamp)
最新推荐文章于 2021-03-12 15:36:56 发布