Roller Coaster Project for python using pandas and matplotlib

so i am creating a function that takes n numbers and a dataframe as an argument to graph the top ranked roller coasters from 2013 to 2018. this is what i have so far and it works but the legend covers too much of the graph, also the colors of the lines start to duplicate after five. how do i make sure each coaster has a unique color and the legend is off of the chart?

def top_coaster_graph(n, df):

top_n_rankings = df[df[‘Rank’] <= n]

fig = plt.figure(figsize=(10, 20))

fig, ax = plt.subplots()

for coaster in set(top_n_rankings[‘Name’]):

coaster_rankings = top_n_rankings[top_n_rankings['Name'] == coaster]

ax.plot(coaster_rankings['Year of Rank'], coaster_rankings['Rank'], label= coaster)


print(top_coaster_graph(10, wood_rankings))

also i created this function to create a bar graph and it is not working when i try it on a parkname and coaster_df
def coaster_inversions(parkname, coaster_df):

park_coasters = coaster_df[coaster_df[‘park’] == parkname]

coaster_names = park_coasters[‘name’]

number_inversions = park_coasters[‘num_inversions’]

fig = plt.figure(figsize=(4, 8))

ax = plt.subplot(), number_inversions)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.