In [1]:
import matplotlib.pyplot as plt
import numpy as np
In [2]:
%matplotlib notebook
In [3]:
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.show()
In [4]:
%matplotlib inline
In [5]:
plt.figure()
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.show()
In [6]:
plt.figure()
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.xlim(x_values.min()*1.1, x_values.max()*1.1)
plt.ylim(y_values.min()*1.1, y_values.max()*1.1)
plt.xlabel('x values')
plt.ylabel('y values')
plt.show()
In [7]:
from matplotlib import style
style.available
Out[7]:
In [8]:
style.use('fivethirtyeight')
plt.figure()
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.xlim(x_values.min()*1.1, x_values.max()*1.1)
plt.ylim(y_values.min()*1.1, y_values.max()*1.1)
plt.show()
In [9]:
%config InlineBackend.figure_format='retina'
In [10]:
plt.figure()
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.xlim(x_values.min()*1.1, x_values.max()*1.1)
plt.ylim(y_values.min()*1.1, y_values.max()*1.1)
plt.show()
In [11]:
%config InlineBackend.figure_formats = {'svg',}
In [12]:
plt.figure()
x_values = np.linspace(-np.pi, np.pi, 256, endpoint=True)
y_values = np.sin(x_values)
plt.plot(x_values, y_values)
plt.xlim(x_values.min()*1.1, x_values.max()*1.1)
plt.ylim(y_values.min()*1.1, y_values.max()*1.1)
plt.show()
As of matplotlib 1.5, pandas dataframes can be plotted by column in plots such as plt.scatter(). To illustrate this capability, let's create a dataframe from a .csv of Pennsylvania fracking data. This dataset is a list of the production of unconventional gas wells for the month of December, 2015.
In [13]:
import pandas as pd
In [15]:
PA_Frack_Wells_Dec = pd.read_csv('gas_data/Oil_Gas_Well_Historical_Production_Report.csv')
PA_Frack_Wells_Dec.head()
Out[15]:
In [18]:
PA_Frack_Wells_Dec.describe()
Out[18]:
We can pass the name of columns to be x and y within plt.scatter as long as we set data equal to the name of the DataFrame which is PA_Frack_Wells_Dec.
In [19]:
style.use('seaborn-notebook')
plt.figure()
plt.scatter(x='Gas_Production_Days',y='Gas_Quantity',data=PA_Frack_Wells_Dec)
plt.xlabel('number of days of gas production')
plt.ylabel('gas production (thousand cubic feet)')
plt.ylim(-20000,PA_Frack_Wells_Dec.Gas_Quantity.max()*1.1)
plt.xlim(0,32)
plt.show()
In [20]:
from mpl_toolkits.basemap import Basemap
style.use('seaborn-notebook')
In [22]:
m = Basemap(projection='mill',
llcrnrlat = 39,
llcrnrlon = -83,
urcrnrlat = 43,
urcrnrlon = -72,
resolution='l')
core_x,core_y = m(PA_Frack_Wells_Dec.Well_Longitude.tolist(),PA_Frack_Wells_Dec.Well_Latitude.tolist())
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='tan',lake_color='lightblue',zorder=0)
m.scatter(x=core_x,y=core_y,c=PA_Frack_Wells_Dec.Gas_Quantity.tolist(),cmap='viridis',vmin=0)
m.colorbar(label='gas quantity (Mcf)')
plt.title('Unconventional gas wells in PA (as of Dec 2015)',)
plt.show()
In [23]:
m = Basemap(projection='mill',
llcrnrlat = 39,
llcrnrlon = -83,
urcrnrlat = 43,
urcrnrlon = -72,
resolution='l')
core_x,core_y = m(PA_Frack_Wells_Dec.Well_Longitude.tolist(),PA_Frack_Wells_Dec.Well_Latitude.tolist())
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='tan',lake_color='lightblue',zorder=0)
m.scatter(x=core_x,y=core_y,c=PA_Frack_Wells_Dec.Gas_Quantity.tolist(),cmap='viridis',vmin=0)
m.readshapefile('./gas_data/marcellus_extent', 'marcellus_extent',color='red',linewidth=1)
m.colorbar(label='gas quantity (Mcf)')
plt.title('Unconventional gas wells in PA (with Marcellus Shale extent)')
plt.show()
In [24]:
high_producing_wells = PA_Frack_Wells_Dec[PA_Frack_Wells_Dec.Gas_Quantity>300000]
m = Basemap(projection='mill',
llcrnrlat = 39,
llcrnrlon = -83,
urcrnrlat = 43,
urcrnrlon = -72,
resolution='l')
core_x,core_y = m(high_producing_wells.Well_Longitude.tolist(),high_producing_wells.Well_Latitude.tolist())
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='tan',lake_color='lightblue',zorder=0)
m.scatter(x=core_x,y=core_y,c=high_producing_wells.Gas_Quantity.tolist(),cmap='viridis',vmin=0)
m.colorbar(label='gas quantity (Mcf)')
plt.title('high producing unconventional gas wells in PA (> 300,000 Mcf)')
plt.show()
In [ ]: