class: center, middle, inverse, title-slide .title[ # Week 5:VisualisingMany Variables ] .author[ ### Visual Data Analytics ] .institute[ ### University of Sydney ] --- # Outline - Using color - All about colormaps - Bubble plot - Facetting - Parallel Coordinates - Spider chart --- # Motivation - Suppose we want to investigate three variables - Whenever we find a relationship between two variables, it is worthwhile asking whether a third variable may be driving that relationship. - For instance suppose there is a relationship between taxi fare and pickup Borough, perhaps this can be explained by distance. --- # Boxplot <img src="05ManyVariables_files/figure-html/unnamed-chunk-3-1.png" width="50%" style="display: block; margin: auto;" /> Manhattan has lower fares --- # What about distance... <img src="05ManyVariables_files/figure-html/unnamed-chunk-4-3.png" width="50%" style="display: block; margin: auto;" /> Fare also depends on distance. --- # Plots in 3D - Initial reaction may be a 3D plot - This can be done in Python - It is very difficult to perceive depth when plot is on a flat screen. - Being able to rotate the plot helps to some extent - Still not ideal. --- # Scatter in 3D <img src="05ManyVariables_files/figure-html/unnamed-chunk-5-5.png" width="50%" style="display: block; margin: auto;" /> --- # Interactive Scatterplot ```python import plotly.express as px fig = px.scatter_3d(taxisdat, x='fare', y='tip', z='distance') fig.write_html('int3d.html') ``` This code will save plot to a html file that can be opened with any browser. --- # Interactive Scatterplot <iframe src="int3d.html" title="3D plot" width="700" height="500"></iframe> --- class: middle, center, inverse # Using color --- # Fare v distance v tip <img src="05ManyVariables_files/figure-html/unnamed-chunk-7-7.png" width="50%" style="display: block; margin: auto;" /> --- # Fare v distance v borough <img src="05ManyVariables_files/figure-html/unnamed-chunk-8-9.png" width="50%" style="display: block; margin: auto;" /> --- # Adding color - The outliers with small distance, high fare also had higher tips. - Perhaps for these trips the taxi driver did something exceptional. - The outliers at top right mostly Queens. - This supports the idea than Manhattan has low fares relative to Queens due to the fact that trips in Manhattan are shorter. - Not definitive causal explanations, but color allows for a richer exploratory understanding of data. --- # Colormaps - There are four types of colormaps - Sequential - Diverging - Cyclic - Qualitative - Following discussion based on [Matplotlib documentation](https://matplotlib.org/stable/tutorials/colors/colormaps.html). --- # Sequential - For most ordinal or numeric variables we use a *sequential* colormap which should be - Perceptually uniform - Large range - Work when printed in black and white - Accessible to colorblind people - Colorful and pretty - The *viridis* colormap (matplotlib default) was developed with these criteria in mind --- # Jet v Viridis A popular palette is jet. <img src="img/jet.jpeg" width="800" style="display: block; margin: auto;" /> A better palette (by the above criteria) is viridis <img src="img/ViridisContinuousContinuous.png" width="3733" style="display: block; margin: auto;" /> --- # Problems with jet - Colors close to one another should be similar. - On jet, in some parts the color changes dramatically over a small range. - Also colorblind people (about 8% of the population) can have difficulty with the red colors in jet. - For more on this see <a href="https://www.youtube.com/watch?list=PLYx7XA2nY5Gcpabmu61kKcToLz0FapmHu&v=xAoljeRJ3lU"> this talk</a> by the creators of viridis. --- # Jet Colormap <img src="img/mona-lisa-rainbow.png" width="384" style="display: block; margin: auto;" /> --- #Viridis colormap <img src="img/mona-lisa-gradient.png" width="384" style="display: block; margin: auto;" /> --- #Colorblindness .pull-left[![](img/notcb.png) Not colorblind] .pull-right[![](img/cb.png) Deuteropia] --- # Divergent colormaps - Central point (usually white or a light color). - Different colors to the left and right. - Colors become darker for more extreme values. - Well suited to data that can be positive or negative (e.g. profit/loss, returns, growth, trade balances). --- # World Bank Data - Will use data sourced from World Bank on European and Central Asian countries in 2015. There are three variables - GDP growth - Net trade - Current account balance --- # Plot ```python wb = pd.read_csv('../data/worldbank.csv', na_values = '..') sns.scatterplot(data = wb, hue='Current Account', y = 'Net Trade', x='GDP growth', palette = 'RdBu') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-13-1.png" width="50%" style="display: block; margin: auto;" /> --- # Match white with 0 ```python import matplotlib.cm as cm import matplotlib.colors as mcolors fig, ax = plt.subplots() wb = pd.read_csv('../data/worldbank.csv', na_values = '..') wb.dropna(axis = 0, how = 'any', inplace = True) vcenter = 0 vmin, vmax = wb['Net Trade'].min(), wb['Net Trade'].max() normalize = mcolors.TwoSlopeNorm(vcenter=vcenter, vmin=vmin, vmax=vmax) colormap = cm.RdBu sns.scatterplot(y=wb['Current Account'],x=wb['GDP growth'],c=wb['Net Trade'],norm=normalize,cmap=colormap,ax=ax,edgecolor='black') scalarmappaple = cm.ScalarMappable(norm=normalize, cmap=colormap) scalarmappaple.set_array(wb['Net Trade']) fig.colorbar(scalarmappaple) plt.show() ``` --- # Match white with 0 ``` ## <matplotlib.colorbar.Colorbar object at 0x7f70493efdc0> ## ## <string>:1: MatplotlibDeprecationWarning: ## ## Unable to determine Axes to steal space for Colorbar. Using gca(), but will raise in the future. Either provide the *cax* argument to use as the Axes for the Colorbar, provide the *ax* argument to steal space from it, or add *mappable* to an Axes. ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-15-3.png" width="50%" style="display: block; margin: auto;" /> --- # Cyclical - As the name implies a cyclical colormap 'wraps' back around on itself. - It is useful for displaying data about angles (e.g wind direction) or calendar effects - The next slide shows taxi fare against distance with day of week mapped to color. - We show code after we discuss time and date objects next week. --- # Cyclical colormap <img src="05ManyVariables_files/figure-html/unnamed-chunk-16-5.png" width="50%" style="display: block; margin: auto;" /> --- # Qualitative Colormap - Used for nominal variables - Ideal for colors to be very different (especially those adjacent on legend) - Avoid reds and greens to make as colorblind friendly as possible. - These is a subtle difference between the default qualitative scheme in Seaborn and the colorblind version. --- # Default ```python sns.scatterplot(data = taxisdat, y='fare', x = 'distance', hue='pickup_borough') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-17-7.png" width="50%" style="display: block; margin: auto;" /> --- # Colorblind Pallette ```python sns.scatterplot(data = taxisdat, y='fare', x = 'distance', hue='pickup_borough', palette = 'colorblind') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-18-9.png" width="50%" style="display: block; margin: auto;" /> --- class: middle, center, inverse # Size and shape --- # More variables - What if we want to include information about a fourth or fifth variable? - We can map a variable to the - Size of the point (bubble plot) - Shape of the point - Use text - We can see some examples --- # Bubble plot ```python sns.scatterplot(data = taxisdat, y='fare', x = 'distance', hue='pickup_borough', size = 'tip', palette = 'colorblind') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-19-11.png" width="50%" style="display: block; margin: auto;" /> --- # Point shapes ```python sns.scatterplot(data = taxisdat, y='fare', x = 'distance', hue='pickup_borough', size = 'tip', style = 'payment', palette = 'colorblind') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-20-13.png" width="50%" style="display: block; margin: auto;" /> --- # Gapminder - A famous example of a bubble chart is Hans Rosling's [gapminder presentation](https://www.youtube.com/watch?v=jbkSRLYSojo). <img src="img/gapminder.jpeg" width="574" style="display: block; margin: auto;" /> --- # Facetting - Notice that bubble plots using many different colors and marker shapes can be overly confusing. - Often it is clearer to use many simpler plots rather than one complicated plot. - This is known as facetting - We can facet with one variable or with two (across rows and columns). --- # Example ```python g = sns.FacetGrid(taxisdat, col="payment", row="color") g.map_dataframe(sns.scatterplot, y = "fare", x = "distance") ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-22-1.png" width="50%" style="display: block; margin: auto;" /> --- # Facetting - Facetting can show roughly which categories have the most observations. - Can show categories with most outliers. - Can show us if and how a relationship between variables can depend on a nominal variable (although not in the previous plot). --- # Facetting by a single variable ```python g = sns.FacetGrid(taxisdat, col="pickup_borough") g.map_dataframe(sns.scatterplot, y = "fare", x = "distance") ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-23-3.png" width="80%" style="display: block; margin: auto;" /> --- # Facetting with wrap ```python g = sns.FacetGrid(taxisdat, col="pickup_borough", col_wrap = 2) g.map_dataframe(sns.scatterplot, y = "fare", x = "distance") ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-24-5.png" width="50%" style="display: block; margin: auto;" /> --- # Other plots ```python g = sns.FacetGrid(taxisdat, col="pickup_borough", col_wrap = 2) g.map_dataframe(sns.histplot, x = "distance") ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-25-7.png" width="50%" style="display: block; margin: auto;" /> --- # A warning - Even if you can display many variables on one plot that does not always mean you *should* do this. - If too many variables are shown it becomes too difficult for the viewer to decode any information. - Complicated plots can be a useful as a step to work out some interesting features in the data. - Then simplify your plot to tell a story --- # Too complicated <img src="05ManyVariables_files/figure-html/unnamed-chunk-26-9.png" width="50%" style="display: block; margin: auto;" /> --- # Pair plots - Combines scatter plots with histograms or KDEs - Can also use color. - The `pairplot` function has an easy interface, but for more flexibility use 'PairGrid' --- # Pair plots ```python sns.pairplot(taxisdat[['distance','fare','tip','tolls','total','payment']],hue='payment') ``` <img src="05ManyVariables_files/figure-html/unnamed-chunk-27-11.png" width="50%" style="display: block; margin: auto;" /> --- # Be careful - Pair plots themselves often contain too much information - In the previous example we may focus on specific things such as - That credit card payments are more right skewed than cash payments - That tolls concentrate around two main values - There is no tip for cash payments - Other plots could then be used to highlight these insights. --- class: middle, center, inverse # A few more plots --- #Parallel coordinates - The parallel coordinates plot mainly works for numeric data - Each variable is standardised so they can be plotted on the same vertical axis. - The variables are displayed horizontally. - Color can be used to show a nominal variable. - Implementation in plotly --- # Wholesale data - For this example we will use a different dataset. - Six numerical variables indicating spending in a different product categories (milk, frozen, detergents, etc.) - Two categorical variables - Region (one of three regions in Portugal) - Channel (client is either retail or hotel/restaurant/cafe) - Data made available by M. Cardoso at [UC Irvine Machine Learning repository](https://archive.ics.uci.edu/ml/datasets/Wholesale+customers) --- # Wholesale data ```python ws = pd.read_csv('../data/wholesale.csv') ws ``` ``` ## Channel Region Fresh ... Frozen Detergents_Paper Delicassen ## 0 2 3 12669 ... 214 2674 1338 ## 1 2 3 7057 ... 1762 3293 1776 ## 2 2 3 6353 ... 2405 3516 7844 ## 3 1 3 13265 ... 6404 507 1788 ## 4 2 3 22615 ... 3915 1777 5185 ## .. ... ... ... ... ... ... ... ## 435 1 3 29703 ... 13135 182 2204 ## 436 1 3 39228 ... 4510 93 2346 ## 437 2 3 14531 ... 437 14841 1867 ## 438 1 3 10290 ... 1038 168 2125 ## 439 1 3 2787 ... 65 477 52 ## ## [440 rows x 8 columns] ``` --- # Parallel coordinates ```python import plotly.express as px fig = px.parallel_coordinates(ws, color="Channel", dimensions=['Fresh', 'Milk', 'Grocery', 'Frozen','Detergents_Paper', 'Delicassen']) ``` ``` ## /home/anastasios/anaconda3/lib/python3.8/site-packages/plotly/express/_core.py:279: FutureWarning: ## ## iteritems is deprecated and will be removed in a future version. Use .items instead. ``` ```python fig.write_html('parcor.html') ``` --- # Parallel Coordinates <iframe src="parcor.html" title="Parallel Coordinates" width="700" height="500"></iframe> --- # Spider/radar chart - Imagine we take a parallel coordinates plot and wrap it around a circle. - This gives a spider or radar plot. - The spider plot is best used for comparing two or three observations across multiple variables. --- # A fun example <img src="img/messivronaldo.jpeg" width="500" height="350" /> Courtesy of twitter user BayernLM10 --- # Other uses - Comparing between two or three observations is surprisingly common - Summary statistics across a small number of groups - Comparing two firms/ products e.g. Apple v Samsung - Comparing the features of two investments. - Can do these using plotly. --- # Plotly code ```python import plotly.graph_objects as go categories = ['Price (1000$)', 'Weight (kg)', 'Display (in)','USB Ports','Runtime(hrs)', 'RAM(GB)', 'Storage(100GB)'] fig = go.Figure() fig.add_trace(go.Scatterpolar( r=[3.997,2.15, 16.2, 3, 14, 16, 10.24], theta=categories, fill='toself', name='Pro' )) ``` ```{=html} <div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script> <script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script> <div id="ffcbb994-2d71-4eb9-b07e-aebf1101cbb1" class="plotly-graph-div" style="height:100%; width:100%;"></div> <script type="text/javascript"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("ffcbb994-2d71-4eb9-b07e-aebf1101cbb1")) { Plotly.newPlot( "ffcbb994-2d71-4eb9-b07e-aebf1101cbb1", [{"fill":"toself","name":"Pro","r":[3.997,2.15,16.2,3,14,16,10.24],"theta":["Price (1000$)","Weight (kg)","Display (in)","USB Ports","Runtime(hrs)","RAM(GB)","Storage(100GB)"],"type":"scatterpolar"}], {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}}}, {"responsive": true} ) }; </script> </div> ``` --- # More Plotly code ```python fig.add_trace(go.Scatterpolar( r=[1.397,1.29, 13.3, 2, 15, 8, 2.56], theta=categories, fill='toself', name='Air' )) ``` ```{=html} <div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script> <script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script> <div id="215258cb-0f30-4a9d-bf41-80440196a407" class="plotly-graph-div" style="height:100%; width:100%;"></div> <script type="text/javascript"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("215258cb-0f30-4a9d-bf41-80440196a407")) { Plotly.newPlot( "215258cb-0f30-4a9d-bf41-80440196a407", [{"fill":"toself","name":"Pro","r":[3.997,2.15,16.2,3,14,16,10.24],"theta":["Price (1000$)","Weight (kg)","Display (in)","USB Ports","Runtime(hrs)","RAM(GB)","Storage(100GB)"],"type":"scatterpolar"},{"fill":"toself","name":"Air","r":[1.397,1.29,13.3,2,15,8,2.56],"theta":["Price (1000$)","Weight (kg)","Display (in)","USB Ports","Runtime(hrs)","RAM(GB)","Storage(100GB)"],"type":"scatterpolar"}], {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}}}, {"responsive": true} ) }; </script> </div> ``` ```python fig.update_layout( polar=dict( radialaxis=dict( visible=True, range=[0, 17] )), showlegend=True ) ``` ```{=html} <div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script> <script src="https://cdn.plot.ly/plotly-2.16.1.min.js"></script> <div id="27f54cda-e95c-4da0-8893-b6b2e92f7ffd" class="plotly-graph-div" style="height:100%; width:100%;"></div> <script type="text/javascript"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("27f54cda-e95c-4da0-8893-b6b2e92f7ffd")) { Plotly.newPlot( "27f54cda-e95c-4da0-8893-b6b2e92f7ffd", [{"fill":"toself","name":"Pro","r":[3.997,2.15,16.2,3,14,16,10.24],"theta":["Price (1000$)","Weight (kg)","Display (in)","USB Ports","Runtime(hrs)","RAM(GB)","Storage(100GB)"],"type":"scatterpolar"},{"fill":"toself","name":"Air","r":[1.397,1.29,13.3,2,15,8,2.56],"theta":["Price (1000$)","Weight (kg)","Display (in)","USB Ports","Runtime(hrs)","RAM(GB)","Storage(100GB)"],"type":"scatterpolar"}], {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmapgl":[{"type":"heatmapgl","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}},"polar":{"radialaxis":{"visible":true,"range":[0,17]}},"showlegend":true}, {"responsive": true} ) }; </script> </div> ``` ```python fig.write_html('radar.html') ``` --- # Radar plot <iframe src="radar.html" title="Parallel Coordinates" width="700" height="500"></iframe> --- # Radar plot - The plotly code allows you to toggle each product on an off allowing for more comparisons. - One problem is that it does not easily handle different scales of measurement for each variable. - You could standardise between 0 and 1 where these limits imply some minimum and maximum value. - Future versions of plotly should make this rescaling automatic. --- class: middle, center, inverse # Wrap-up --- # Conclusions - There are several ways to show multiple variables on a plot. - Color - Size/shape - Facetting - Do not generate complicated plots for the sake of it. Always look for a story. --- class: middle, center, inverse # Questions