Skip to content

Instantly share code, notes, and snippets.

View erikaris's full-sized avatar

Erika Siregar erikaris

  • Old Dominion University
  • Norfolk, Virginia
View GitHub Profile
# taken from Coursera.org
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
linear_data = np.array([1,2,3,4,5,6,7,8])
exponential_data = linear_data**2
# Modified from Coursera.org
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
linear_data = np.array([1,2,3,4,5,6,7,8])
exponential_data = linear_data**2
# adjust the x-axis labels
# step 1: get the x-axis instance.
# we can do various things on x-axis instance such as axis.get_ticklabels.
# explore other things that we can do on x-axis: https://matplotlib.org/devdocs/api/axis_api.html
ax = plt.gca().get_xaxis()
# ax2 = plt.gca().xaxis
# print(ax)
# print(ax2)
# step 2: get the ticklabels of the Xaxix
# create a multiseries bar chart
# make multiple calls on 'plt.bar()'
# series 1
plt.figure()
xvals = range(len(linear_data))
plt.bar(xvals, linear_data, width = 0.3)
#series 2:
new_xvals = []
from random import randint
plt.figure()
xvals = range(len(linear_data))
plt.bar(xvals, linear_data, width = 0.3)
linear_err = [randint(0,5) for x in range(len(linear_data))]
print(linear_err)
# This will plot a new set of bars with errorbars using the list of random error values
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]
plt.bar(pos, popularity, align='center')
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]
# change the bar colors to be less bright blue
# 100% taken from coursera
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]
import matplotlib.pyplot as plt
import matplotlib.patches as patches
# build a rectangle in axes coords
left, width = .25, .5
bottom, height = .25, .5
right = left + width
top = bottom + height
fig = plt.figure()
#taken from https://matplotlib.org/users/text_props.html
import matplotlib.pyplot as plt
import matplotlib.patches as patches
# build a rectangle in axes coords
left, width = .25, .5
bottom, height = .25, .5
right = left + width
top = bottom + height