While working on a dataset it is important to check the distribution of the data. Obviously, for most of humans it is difficult to visualize the data in more than 3 dimensions
Viz is important to understand the data and to show results. We have already seen there are some basinc viz functionalities in Pandas.
Now we'll discover two of the most know viz libraries in Python:
Viz is important to understand the data and to show results. We have already seen there are some basinc viz functionalities in Pandas.
Now we'll discover two of the most know viz libraries in Python:
- Pandas viz
- Matplotlib
- Plotly
Pandas viz is pratique: rapid plot, relies on Matplotlib. (check matplotlib doc sometimes not all params are detailed in pandas doc)
The goal of this plot is to learn to use Matplotlib to plot data. As you know, Matplotlib is the underlying library used by Pandas. It provides more options to plot custom visualizations. Howerver, most of the plots we will create with Matplotlib can be reproduced with Pandas' `.plot()`.
The goal of this plot is to learn to use Matplotlib to plot data. As you know, Matplotlib is the underlying library used by Pandas. It provides more options to plot custom visualizations. Howerver, most of the plots we will create with Matplotlib can be reproduced with Pandas' `.plot()`.
1. Reproduce this plot. We assume the datapoints have integers coordinates.
1. Reproduce this plot. We assume the datapoints have integers coordinates.
The goal of this plot is to learn to use Matplotlib to plot different lines in the same plot on different axis using `twinx`. This very useful to compare variables in different ranges.
Here is the data:
The goal of this plot is to learn to use Matplotlib to plot different lines in the same plot on different axis using `twinx`. This very useful to compare variables in different ranges.
Check that the plot has been created with a for loop.
Check that the plot has been created with a for loop.
# Exercise 6 Plotly 1
Plotly has evolved a lot in the previous years. It is important to **always check the documentation**.
Plotly comes with a high level interface: Plotly Express. It helps building some complex plots easily. The lesson won't detail the complex examples. Plotly express is quite interesting while using Pandas Dataframes because there are some built-in functions that leverage Pandas Dataframes.
Plotly has evolved a lot in the previous years. It is important to **always check the documentation**.
The plot outputed by Plotly is interactive and can also be dynamic.
Plotly comes with a high level interface: Plotly Express. It helps building some complex plots easily. The lesson won't detail the complex examples. Plotly express is quite interesting while using Pandas Dataframes because there are some built-in functions that leverage Pandas Dataframes.
The goal of the exercise is to plot the price of a company. Its price is generated below.
The plot outputed by Plotly is interactive and can also be dynamic.
```
The goal of the exercise is to plot the price of a company. Its price is generated below.
1. Using Plotly express, reproduce the plot in the image. As the data is generated randomly I do not expect you to reproduce the same line.
1. Using Plotly express, reproduce the plot in the image. As the data is generated randomly I do not expect you to reproduce the same line.
![alt text][logo_ex6]
[logo_ex6]: images/day03/w1day03_ex6_plot1.png "Time series ex6"
The plot has to contain:
The plot has to contain:
- title
- title
- x-axis name
- yaxis name
2. Same question but now using `plotly.graph_objects`. You may need to use `init_notebook_mode` from `plotly.offline`.
2. Same question but now using `plotly.graph_objects`. You may need to use `init_notebook_mode` from `plotly.offline`.
https://plotly.com/python/time-series/e
## Correction
1. This question is validated if the plot is in the image is reproduced using Plotly express given those criterias:
1. This question is validated if the plot is in the image is reproduced using Plotly express given those criteria:
The plot has to contain:
The plot has to contain:
- a title
- a title
- x-axis name
- yaxis name
![alt text][logo_ex6]
[logo_ex6]: images/day03/w1day03_ex6_plot1.png "Time series ex6"
2.This question is validated if the plot is in the image is reproduced using `plotly.graph_objects` given those criterias:
2.This question is validated if the plot is in the image is reproduced using `plotly.graph_objects` given those criteria:
The plot has to contain:
The plot has to contain:
- a title
- a title
- x-axis name
- yaxis name
@ -286,32 +282,34 @@ The plot has to contain:
# 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 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.
Let us generate 3 random arrays from a normal distribution. And for each array add respectively 1, 2 to the normal distribution.
Let us generate 3 random arrays from a normal distribution. And for each array add respectively 1, 2 to the normal distribution.
```
```python
y0 = np.random.randn(50)
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. Plot in the same Figure 2 box plots as shown in the image. In this exercise the style is not important.