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]

  fig = plt.figure()
  ax1 = fig.add_subplot(1,2,1)
  ax2 = fig.add_subplot(1,2,2)

  ax1.set(xlim =(0,13),ylim = (10,110),xlabel= "month_2013",ylabel = "temperature_2013",title = "2013" )
  ax1.scatter(month,temperature,color = "darkblue",marker = "o")
  ax2.set(xlim =(0,13),ylim = (10,110),xlabel= "month_2014",ylabel = "temperature_2014",title = "2014" )
  ax2.scatter(month,temperature, color = "darkgreen",marker = "o")

  plt.show()

时间: 2024-08-07 04:31:40

Data Visualizations 4的相关文章

Data Visualizations 6

Visualize Geographic Data: To deal with mutiple DataFrame 1. How to install a library into the Anaconda: In Jupyter Notebook, under tag Conda, we can install packages and save them into Anaconda > Lib > site-packages folder 2. Create a basemap insta

Data Visualizations 7

1. If we create a DataFrame, each of the column inside of it is already a set of Series. Does not necessary to change them into a one-column Dataframe. 2. Here we use scatter_matrix function to plot the DataFrame: normal_movies = hollywood_movies[hol

Data Visualizations 2

1.Histogram : A histogram is a graph that enables you to visualize the distribution of values of a column. Example: import matplotlib.pyplot as plt columns = ['Median','Sample_size'] recent_grads.hist(column=columns)# to visulize the column "Median&q

Data Visualizations 1

1.Independent variables : each variable is saperate from others in the dataset. 2.Data scatter: weight = [600,150,200,300,200,100,125,180] height = [60,65,73,70,65,58,66,67] # dataset import matplotlib.pyplot as plt # import pyplot from matplotlib pl

Data Visualizations 3

Data Cleaning and visualization: 1.Before cleaning a set of data, we need to inspect the data by using shape(),head(),dtype(),decribe() function. 2.First, we are going to deal with the missing data.(by using dropna() or loc[]) 3.Second, we are going

Data Visualizations 5

To genereate a bar chart with matplotlib: ////////////////////////////////Import libraries and classes///////////////////////////////////////////////////////////////////// import pandas as pd import matplotlib.pyplot as plt import seaborn as sns impo

R8:Learning paths for Data Science[continuous updating…]

Comprehensive learning path – Data Science in Python Journey from a Python noob to a Kaggler on Python So, you want to become a data scientist or may be you are already one and want to expand your tool repository. You have landed at the right place.

data cleaning

Cleaning data in Python Table of Contents Set up environments Data analysis packages in Python Clean data in Python Load dataset into Spyder Subset Drop data Transform data Create new variables Rename variables Merge two datasets Handle missing value

7 Tools for Data Visualization in R, Python, and Julia

7 Tools for Data Visualization in R, Python, and Julia Last week, some examples of creating visualizations with htmlwidgets and R were presented. Fortunately, there are many more options available for creating nice visualizations. Tools and libraries