Basic Graphing Functions with Pandas

Importing Package and Developing Data

In [13]:
import pandas as pd
import matplotlib.pyplot as plt
import random
%matplotlib inline
In [14]:
rand_Data_x = [random.randrange(4, 100, 1) for i in range(50)]
print(rand_Data_x)
[66, 76, 70, 48, 49, 23, 4, 9, 60, 9, 4, 83, 72, 37, 5, 19, 42, 74, 82, 49, 43, 18, 90, 70, 59, 62, 89, 97, 85, 39, 47, 24, 66, 27, 67, 46, 68, 84, 64, 10, 12, 50, 20, 80, 65, 62, 23, 19, 30, 84]
In [15]:
rand_Data_y = [random.randrange(4, 100, 1) for i in range(50)]
print(rand_Data_y)
[71, 61, 78, 87, 46, 19, 29, 27, 51, 91, 92, 74, 17, 16, 64, 56, 96, 28, 31, 23, 86, 84, 76, 89, 48, 9, 66, 48, 31, 55, 28, 50, 45, 52, 12, 78, 51, 25, 83, 44, 12, 54, 69, 38, 84, 38, 57, 43, 62, 67]

Scatterplot

In [19]:
fig, ax = plt.subplots() # To return a figure and single axes
ax.scatter(rand_Data_x, rand_Data_y, alpha = .25, c = 'k') # Estblishing x and y axes, dot transparency, and dot color.
fig.set_size_inches(13,8) # Setting graph size

fig.suptitle('Demonstration of Scatterplot with Randomness') # Graph Title
ax.xaxis.set_label_text('x-axis Values') # X axis label
ax.yaxis.set_label_text('y-axis Values') # Y axis label
plt.savefig('Scatterplot with Randomness.png')
plt.show() # Displaying the graph in the Jupyter notebook

Bar Chart

In [26]:
xTotal = [(rand_Data_x[i],rand_Data_y[i]) for i in range(len(rand_Data_x))]
xTotal.sort(key = lambda x:x[1], reverse=True)
xNumbers = [x[0] for x in xTotal[:6]]  #[:6]
Plot = [x[1] for x in xTotal[:6]]  #[:6]

fig,ax = plt.subplots()
ax.bar(xNumbers,Plot)
plt.show()