Data Visualization - New
Data Visualization - New
AREA PLOT
- Also know as area chart or area graph.
- Commonly used to represent cumulated totals using numers or percentages over time.
- Is commonly used when trying to compare two or more quantities.
- df_top5.index = df_top5.index.map(int) # let's change the index values of df_top5 to type integer
for plotting
- df_top5.plot(kind='area', stacked=False,figsize=(20, 10), # pass a tuple (x, y) size)
- plt.title('Immigration Trend of Top 5 Countries')
- plt.ylabel('Number of Immigrants')
- plt.xlabel('Years')
- plt.show()
HISTOGRAMS
- Import matplotlib as mpl
- Import matplotlib.pyplot as plt
- Df_canada['2013'].plot(kind = 'hist', figsize = (10,6))
- Plt.title('Histogram of immigration from 195 countries in 2013')
- Plt.ylabel('Number of countries')
- Plt.xlabel('Number of immigrants')
- Plt.show()
BINS HISTOGRAMA
- # transpose dataframe
- df_t = df_can.loc[['Denmark', 'Norway', 'Sweden'], years].transpose()
- df_t.head()
- To create a bar plot, we can pass one of two arguments via kind parameter in plot():
- kind=bar creates a vertical bar plot
- kind=barh creates a horizontal bar plot
Let's annotate this on the plot using the annotate method of the scripting layer or the pyplot
interface. We will pass in the following parameters:
# Annotate arrow
plt.annotate("",# s: str. Will leave it blank for no text
xy=(32, 70), # place head of the arrow at point (year 2012 , pop 70)
xytext=(28, 20), # place base of the arrow at point (year 2008 , pop 20)
xycoords='data', # will use the coordinate system of the object being annotated
arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='blue', lw=2)
)
# annotate value labels to each country
# place text at the end of bar (subtracting 47000 from x, and 0.1 from y to make it fit within the
bar)
Unlike a histogram, a bar chart is commonly used to compare the values of a variable at a given point in
time.
# let's examine the types of the column labels