Data Visualizations 4

So far, I have learn some types of plotting methods:

  • Matplotlib's high-level plotting methods - e.g. .scatter().plot()
  • Seaborn's high-level plotting methods - e.g. .distplot().boxplot()
  • Pandas DataFrame methods - e.g. .hist().boxplot()

High level plotting method like scatter(), only need to input the data and the function will take care the rest of the part. Low level plotting allows users do more customization.

1. Figure, Plot. Figsize(), add_subplot() function.

  import matplotlib.pyplot as plt # import the function

  %matplotlib inline # Make sure that all the plots are inline

  fig = plt.figure(figsize=(5,7)) # Create a figure which is 5 inch width, 7 inch high

  ax = fig.add_subplot(3,3,2) # Create 3 plots inside the figure, the width for each of them is 1/3 of the figure width. The height for each plot is 1/3 of figure height. And we display the second plot.
  
plt.show()

2. Axes:  A Subplot is an abstraction that creates an Axes object whenever you call .add_subplot(). An Axes object controls how the plotting actually happens. The Axes object describes what's actually inside the plot we're interested in (like the points in a scatter plot) and also describes the x and y axes, including the ticks, labels, etc. 

 While each Figure instance can contain multiple plots, and therefore multiple Axes objects, that specify how each plot looks, each unique Axes object can only belong to one figure.

3.   ax.set_xlim([1,12]) # set the range of ticks for x 

    ax.set_ylim([15,105])# set the range of ticks for y 

4.  Example:

  month_2013 = [1,2,3,4,5,6,7,8,9,10,11,12]
  temperature_2013 = [32,18,40,40,50,45,52,70,85,60,57,45]
  month_2014 = [1,2,3,4,5,6,7,8,9,10,11,12]
  temperature_2014 = [35,28,35,30,40,55,50,71,75,70,67,49]# Here are data list

  fig = plt.figure() # To create a figure and assign into fig
  ax1 = fig.add_subplot(1,2,1) # add one plot has full width and 1/2 height of the figure
  ax2 = fig.add_subplot(1,2,2) # add second plot has full width and 1/2 height of the figure 

  ax1.set(xlim =(0,13),ylim = (10,110),xlabel= "month_2013",ylabel = "temperature_2013",title = "2013" ) # setup the first plot
  ax1.scatter(month,temperature,color = "darkblue",marker = "o") # set the frist plot as scatter with darkblue background and "0" marker
  ax2.set(xlim =(0,13),ylim = (10,110),xlabel= "month_2014",ylabel = "temperature_2014",title = "2014" ) # setup the second plot
  ax2.scatter(month,temperature, color = "darkgreen",marker = "o") # same as ax1 scatter

  plt.show()

转载于:https://www.cnblogs.com/kingoscar/p/5958933.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值