feat(visualizations): clarify exercise 7

This commit is contained in:
nprimo 2023-11-24 11:38:22 +00:00 committed by Niccolò Primo
parent 0bd7f3f1c8
commit d87d5a5df4
3 changed files with 9 additions and 23 deletions

View File

@ -247,9 +247,10 @@ https://plotly.com/python/time-series/
# Exercise 7: Plotly Box plots
The goal of this exercise is to learn to use Plotly to plot Box Plots. It is t is a method for graphically depicting groups of numerical data through their quartiles and values as min, max. It allows to compare quickly some variables.
The goal of this exercise is to learn to use Plotly to plot Box Plots. It is a method for graphically depicting groups of numerical data through their quartiles and values as min, max. It allows comparing quickly some variables.
Let us generate 3 random arrays from a normal distribution. And for each array add respectively 1, 2 to the normal distribution.
Generate 3 random arrays from a normal distribution. Keep one as it is and for
the other two arrays add respectively 1 and 2 to the normal distribution.
```python
y0 = np.random.randn(50)
@ -257,7 +258,7 @@ y1 = np.random.randn(50) + 1 # shift mean
y2 = np.random.randn(50) + 2
```
1. Plot in the same Figure 2 box plots as shown in the image. In this exercise the style is not important.
1. In the same figure, plot the 3 distributions as box plots as shown in the image. In this exercise the style is not important.
![alt text][logo_ex7]

View File

@ -145,29 +145,14 @@ https://matplotlib.org/gallery/api/two_scales.html
#### Exercise 7: Plotly Box plots
###### For question 1, does the plot reproduce the plot in the image and respect those criteria? The code below shows a solution.
###### For question 1, does the plot reproduce the plot in the image as asked in the subject?
###### Does it have a title?
###### Does the figure as 3 box plots?
###### Does it have a legend?
###### Does the 3 box plots show normal distributions around 0, 1 and 2 respectively?
Due to the random nature of the distributions, the two graphs do not require a perfect match
![alt text][logo_ex7]
[logo_ex7]: ../w1day03_ex7_plot1.png "Box plot ex7"
```python
import plotly.graph_objects as go
import numpy as np
y0 = np.random.randn(50)
y1 = np.random.randn(50) + 1 # shift mean
y2 = np.random.randn(50) + 2
fig = go.Figure()
fig.add_trace(go.Box(y=y0, name='Sample A',
marker_color = 'indianred'))
fig.add_trace(go.Box(y=y1, name = 'Sample B',
marker_color = 'lightseagreen'))
fig.show()
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 22 KiB