Introduction to Data Visualization with Python(datacamp)

  • Customizing plots
    1. 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()
      
      
      
    2. 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')
      
    3. 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
    1. 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)
      
    2. 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()
      
    3. Visualizing bivariate distributions

      #Histograms in 2D
      #Common choices : rectangles & hexagons
      plt.hist2d(x, y, bins=(___,___))
      plt.colorbar()
      
      plt.hexbin(x, y, gridsize=(___,___))
      plt.colorbar()
      
    4. 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
    1. 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
      
    2. 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
      
    3. 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
    1. Visualizing times series

      #make formatted label
      labels = dates.striftime('%b %d')
      print (labels)
      ['Jan 01',...]
      
      #xtick
      plt.xticks(dates, labels, rotation=___)
      
    2. Time series with moving windows

      # A 'moving window' refers to a time interval in a time
      !!!!!!!!!!!!!!待补充
      
    3. 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()
      
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值