In [27]:
"""
simple demo of a horizontal bar chart
"""
import pandas
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
In [28]:
plt.rcdefaults()
In [29]:
fig, ax = plt.subplots()
# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))
In [30]:
ax.barh(y_pos, performance, xerr=error, align='center',
color='green', ecolor='black')
Out[30]:
In [31]:
ax.set_yticks(y_pos)
Out[31]:
In [32]:
ax.set_yticklabels(people)
Out[32]:
In [33]:
ax.invert_yaxis()
In [34]:
ax.set_xlabel('Performance')
Out[34]:
In [35]:
ax.set_title('How fast do you want to go today?')
Out[35]:
In [36]:
plt.show()
In [37]:
x = np.linspace(0, 1, 500)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
fig, ax = plt.subplots()
ax.fill(x, y, zorder=10)
ax.grid(True, zorder=5)
plt.show()
In [39]:
forest_fires = pandas.read_csv('../data/forestfire/forestfires.csv')
In [40]:
forest_fires.head(5)
Out[40]:
In [41]:
weight = [600, 150, 200, 300, 200, 100, 125, 180]
In [42]:
height = [60, 65, 73, 70, 65, 58, 66, 67]
In [43]:
len(weight), len(height)
Out[43]:
In [44]:
plt.scatter(height, weight)
plt.show()
In [47]:
plt.scatter(forest_fires["wind"], forest_fires["area"])
plt.title('Wind speed vs fire area')
plt.xlabel('Wind speed when fire started')
plt.ylabel('Area consumed by fire')
plt.show()
In [48]:
age = [5, 10, 15, 20 ,25, 30]
height = [25, 45, 65, 75, 75, 75]
plt.plot(age, height)
plt.title('Age vs Height')
plt.xlabel('age')
plt.ylabel('Height')
plt.show()
In [49]:
area_by_month = forest_fires.pivot_table(index="month", values="area",aggfunc=np.sum)
In [50]:
type(area_by_month)
Out[50]:
In [52]:
plt.bar(range(len(area_by_month)), area_by_month)
plt.title('Month vs Area')
plt.xlabel('month')
plt.ylabel('area')
plt.show()
In [53]:
plt.barh(range(len(area_by_month)), area_by_month)
plt.title('Month vs Area')
plt.xlabel('month')
plt.ylabel('area')
plt.show()
In [54]:
plt.style.use('fivethirtyeight')
plt.plot(forest_fires['rain'], forest_fires['area'])
plt.show()
In [57]:
plt.style.use('bmh')
plt.plot(forest_fires['rain'], forest_fires['area'])
plt.show()
In [ ]: