Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelGomezCorral committed Dec 21, 2024
2 parents 3070139 + 4540b30 commit 328d712
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions data_analysis/interactive_plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6713,9 +6713,9 @@
"fig.update_layout(\n",
" title=\"Themes in genres\",\n",
" legend=dict(\n",
" x=-0.8, # Horizontal position (0 = far left, 1 = far right)\n",
" y=0.9, # Vertical position (0 = bottom, 1 = top)\n",
" title=\"Topic\" # Optional: Add a legend title\n",
" x=-0.8, \n",
" y=0.9, \n",
" title=\"Topic\" \n",
" ),\n",
" width=800,\n",
" height=800\n",
Expand Down Expand Up @@ -11333,7 +11333,7 @@
" label=age,\n",
" method='update',\n",
" args=[\n",
" {'visible': [i == idx for i in range(len(df_age.index.values))]}, # Toggle visibility\n",
" {'visible': [i == idx for i in range(len(df_age.index.values))]}, \n",
" {'title': f\"Genre: {age}\"} \n",
" ]\n",
" )\n",
Expand Down Expand Up @@ -365986,20 +365986,17 @@
"from collections import Counter\n",
"import heapq\n",
"\n",
"# Assuming MOVIES DataFrame and required columns are already defined\n",
"column = ['vote_average','revenue', 'budget']\n",
"unique_genre = []\n",
"\n",
"# Extract unique genres\n",
"MOVIES[\"new_genres\"].apply(lambda x: unique_genre.extend(ast.literal_eval(x)))\n",
"\n",
"counted_genre = Counter(unique_genre)\n",
"unique_genre = heapq.nsmallest(5, counted_genre, key=counted_genre.get)\n",
"fig = go.Figure()\n",
"unique_genre=['Romance', 'Horror']\n",
"# Create a dictionary to store traces by genre\n",
"\n",
"for idx, genre in enumerate(unique_genre):\n",
" # Filter data for the specific genre\n",
" df_temp = MOVIES[MOVIES[\"new_genres\"].apply(lambda x: genre in ast.literal_eval(x))]\n",
" df_temp = df_temp[column+[\"name\"]]\n",
" df_temp = df_temp[(df_temp != 0).all(axis=1)]\n",
Expand All @@ -366012,7 +366009,6 @@
" ))\n",
"\n",
"sizeref = 10\n",
"# Tune marker appearance and layout\n",
"fig.update_traces(mode='markers', marker=dict(sizemode='area', line_width=2, sizeref=sizeref, line=dict(width=2,color='DarkSlateGrey')))\n",
"\n",
"fig.update_layout(\n",
Expand All @@ -366034,7 +366030,7 @@
")\n",
"\n",
"fig.update_layout(\n",
" clickmode=\"event+select\" # Allows selecting a point and its corresponding trace\n",
" clickmode=\"event+select\" \n",
"\n",
")\n",
"fig.show()\n",
Expand Down Expand Up @@ -546802,7 +546798,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -547095,30 +547091,28 @@
"genre_df['group'] = genre_df['group'].apply(lambda x: int(x))\n",
"\n",
"# https://python-graph-gallery.com/231-chord-diagram-with-bokeh/\n",
"# libraries\n",
"\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"from holoviews import opts, dim\n",
"from bokeh.sampledata.les_mis import data\n",
"from bokeh.plotting import figure, output_file, save\n",
"\n",
"# Should the diagram be plotted with 'bokeh' or 'matplotlib'?\n",
"\n",
"hv.extension('bokeh')\n",
"# How large should be the diagram?\n",
"\n",
"hv.output(size=300)\n",
"\n",
"# Data set\n",
"nodes = hv.Dataset(genre_df, 'index')\n",
"links = df\n",
"\n",
"# Chord diagram\n",
"\n",
"chord = hv.Chord((links, nodes)).select(value=(5, None))\n",
"chord.opts(\n",
" opts.Chord(cmap='Category20', edge_cmap='Category20', edge_color=dim('source').str(), \n",
" labels='name', node_color=dim('index').str()))\n",
"\n",
"# Not needed in a jupyter notebook\n",
"# It shows the diagram when run in another IDE or from a python script:\n",
"\n",
"from bokeh.plotting import show\n",
"output_file('chord_plot.html', mode='inline')\n",
"save(hv.render(chord))\n",
Expand Down

0 comments on commit 328d712

Please sign in to comment.