From 38c88b29c7948d6960a98ac2281214ad13e88ca1 Mon Sep 17 00:00:00 2001 From: Justin <127172022+jl33-ai@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:20:45 +1100 Subject: [PATCH 1/3] Create migrate.py --- migrate.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 migrate.py diff --git a/migrate.py b/migrate.py new file mode 100644 index 0000000..611fecc --- /dev/null +++ b/migrate.py @@ -0,0 +1,43 @@ +# Let's start from the beginning with improved code +import pandas as pd +import matplotlib.pyplot as plt +import seaborn as sns +sns.set(rc={'axes.facecolor': 'lavender'}) # Background color for the plot +%matplotlib inline + +# Get data +ratings = pd.read_csv('ratings.csv', encoding='iso8859') + +# Sort values by rating +ratings = ratings.sort_values(by=['Your Rating']) + +# Loop to create a new variable, which will turn scatterplot to a dot plot +movie_count = [] + +for index, year in enumerate(ratings['Year']): + subset = ratings.iloc[:index + 1] # Create subset starting at the beginning of dataset until the movie itself + count = len(subset[subset['Year'] == year]) # Count all movies from the same year in this subset + movie_count.append(count) # Appended counts will be used as vertical values in the scatterplot, + # which will help to create a dot plot + +# Data for the plot +x = ratings['Year'] +y = movie_count +hue = ratings['Your Rating'] + +# Dot plot created using scatter plot +plt.figure(figsize=(15, 10)) +ax = sns.scatterplot(x, y, hue=hue, s=60, legend="full", palette="RdYlGn") +ax.grid(False) # Remove grid +ax.get_legend().remove() # Delete default legend +scale_legend = plt.Normalize(hue.min() - 1, hue.max()) # Create a scale for the colormap. +# hue.min-1 because I never rated a movie 1/10, but still wanted to create a consistent color map. +color_map = plt.cm.ScalarMappable(cmap="RdYlGn", norm=scale_legend) # Colormap used in legend. +color_map.set_array([]) # Dummy variable needed to create a colormap. +ax.figure.colorbar(color_map) # Add colormap as a legend. +plt.xlim([1950, 2020]) # There are just few movies I seen from before 1950. +plt.ylabel("Count", size=14) +plt.xlabel("Release year", size=14) +plt.title("Movies seen by year and rating", size=20) +plt.gcf().text(0.83, 0.5, "Rating", fontsize=14, rotation=90) # Label used for colormap. +plt.show() From 9edc1518be38873a5f11cdf1001fafd93b8d8916 Mon Sep 17 00:00:00 2001 From: Justin <127172022+jl33-ai@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:26:51 +1100 Subject: [PATCH 2/3] Update migrate.py --- migrate.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/migrate.py b/migrate.py index 611fecc..dafe9ee 100644 --- a/migrate.py +++ b/migrate.py @@ -41,3 +41,30 @@ plt.title("Movies seen by year and rating", size=20) plt.gcf().text(0.83, 0.5, "Rating", fontsize=14, rotation=90) # Label used for colormap. plt.show() + + +# +=====================================+ +sns.set(rc={'axes.facecolor': 'lavender'}) # Background color for the plot + +# Dot plot created using scatter plot +plt.figure(figsize=(20, 2)) + +include_ongoing = str(input("Do you want to include the current, unresolved tickets? (Y/N): ")).lower() +if include_ongoing == 'y': + # Scatterplot for NaN data. + ax = sns.scatterplot(x=data_na['arrival_date'], y=tickets_by_day_count_na, + color='#142c5c', s=DOT_SIZE, legend=False) + ax.xaxis.set_major_locator(mdates.DayLocator(interval=15)) + +# Scatterplot for non-NaN data. +ax = sns.scatterplot(x=data_not_na['arrival_date'], y=tickets_by_day_count, + hue=data_not_na['full_resolution_time_standardized'], s=DOT_SIZE, + legend="full", palette="RdYlGn") +ax.xaxis.set_major_locator(mdates.DayLocator(interval=15)) + +ax.grid(False) +ax.get_legend().remove() +plt.ylabel("Ticket Count", size=14) +plt.ylim([0, 18]) +plt.xlabel("Date", size=14) +plt.show() From 29ba66dffb192e012de753a86d9505ecff84de03 Mon Sep 17 00:00:00 2001 From: Justin <127172022+jl33-ai@users.noreply.github.com> Date: Thu, 11 Jan 2024 21:03:28 +1100 Subject: [PATCH 3/3] Delete migrate.py --- migrate.py | 70 ------------------------------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 migrate.py diff --git a/migrate.py b/migrate.py deleted file mode 100644 index dafe9ee..0000000 --- a/migrate.py +++ /dev/null @@ -1,70 +0,0 @@ -# Let's start from the beginning with improved code -import pandas as pd -import matplotlib.pyplot as plt -import seaborn as sns -sns.set(rc={'axes.facecolor': 'lavender'}) # Background color for the plot -%matplotlib inline - -# Get data -ratings = pd.read_csv('ratings.csv', encoding='iso8859') - -# Sort values by rating -ratings = ratings.sort_values(by=['Your Rating']) - -# Loop to create a new variable, which will turn scatterplot to a dot plot -movie_count = [] - -for index, year in enumerate(ratings['Year']): - subset = ratings.iloc[:index + 1] # Create subset starting at the beginning of dataset until the movie itself - count = len(subset[subset['Year'] == year]) # Count all movies from the same year in this subset - movie_count.append(count) # Appended counts will be used as vertical values in the scatterplot, - # which will help to create a dot plot - -# Data for the plot -x = ratings['Year'] -y = movie_count -hue = ratings['Your Rating'] - -# Dot plot created using scatter plot -plt.figure(figsize=(15, 10)) -ax = sns.scatterplot(x, y, hue=hue, s=60, legend="full", palette="RdYlGn") -ax.grid(False) # Remove grid -ax.get_legend().remove() # Delete default legend -scale_legend = plt.Normalize(hue.min() - 1, hue.max()) # Create a scale for the colormap. -# hue.min-1 because I never rated a movie 1/10, but still wanted to create a consistent color map. -color_map = plt.cm.ScalarMappable(cmap="RdYlGn", norm=scale_legend) # Colormap used in legend. -color_map.set_array([]) # Dummy variable needed to create a colormap. -ax.figure.colorbar(color_map) # Add colormap as a legend. -plt.xlim([1950, 2020]) # There are just few movies I seen from before 1950. -plt.ylabel("Count", size=14) -plt.xlabel("Release year", size=14) -plt.title("Movies seen by year and rating", size=20) -plt.gcf().text(0.83, 0.5, "Rating", fontsize=14, rotation=90) # Label used for colormap. -plt.show() - - -# +=====================================+ -sns.set(rc={'axes.facecolor': 'lavender'}) # Background color for the plot - -# Dot plot created using scatter plot -plt.figure(figsize=(20, 2)) - -include_ongoing = str(input("Do you want to include the current, unresolved tickets? (Y/N): ")).lower() -if include_ongoing == 'y': - # Scatterplot for NaN data. - ax = sns.scatterplot(x=data_na['arrival_date'], y=tickets_by_day_count_na, - color='#142c5c', s=DOT_SIZE, legend=False) - ax.xaxis.set_major_locator(mdates.DayLocator(interval=15)) - -# Scatterplot for non-NaN data. -ax = sns.scatterplot(x=data_not_na['arrival_date'], y=tickets_by_day_count, - hue=data_not_na['full_resolution_time_standardized'], s=DOT_SIZE, - legend="full", palette="RdYlGn") -ax.xaxis.set_major_locator(mdates.DayLocator(interval=15)) - -ax.grid(False) -ax.get_legend().remove() -plt.ylabel("Ticket Count", size=14) -plt.ylim([0, 18]) -plt.xlabel("Date", size=14) -plt.show()