Skip to content

Commit

Permalink
GitBook: [master] 79 pages and 11 assets modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivy authored and gitbook-bot committed Jul 26, 2020
1 parent dc00c79 commit bb328e8
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 0 deletions.
Binary file added .gitbook/assets/dendrogram-explained.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/newplot-2- (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/newplot-3- (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/newplot-3- (2).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/newplot-4- (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .gitbook/assets/newplot-5-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions plotly/6.2-basic-charts/6.2.5-tables.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,125 @@
# 6.2.6 Tables

There are two methods to create a table in Plotly. One is `plotly.graph_objects,` the other is `plotly.figure_factory`

## Graph Objects

### 1. Basic Table

```text
import plotly.graph_objects as go
fig = go.Figure(data=[go.Table(header=dict(values=['Jonas', 'Melo']),
cells=dict(values=[[100, 90, 80, 85], [90, 85, 88, 65]]))
])
fig.show()
```

![](../../.gitbook/assets/screenshot-2020-07-26-at-22.34.47.png)

### 2. Customized Table

```text
fig = go.Figure(data=[go.Table(
header=dict(values=['Jonas', 'Melo'],
line_color='silver',
fill_color='navy',
align='center',
font=dict(color='white', size=14),
height=40),
cells=dict(values=[[100, 90, 80, 85], # 1st column
[90, 85, 88, 65]], # 2nd column
line_color='silver',
fill_color='aliceblue',
align='left'))
])
fig.update_layout(width=500, height=300)
fig.show()
```

![](../../.gitbook/assets/screenshot-2020-07-26-at-22.34.41.png)

## Figure Factory

### 3. Basic Table

```text
import plotly.figure_factory as ff
data_matrix = [['Name', 'Semester', 'Score'],
['Jonas', 1, 'A+'],
['Melo', 1, 'B+'],
['Jonas', 2, 'A'],
['Melo', 2, 'A']]
fig = ff.create_table(data_matrix)
fig.show()
```

![](../../.gitbook/assets/newplot-3-%20%281%29.png)

### 4. Table with LaTeX

{% hint style="info" %}
The default row height is 30 pixels. We can use \ **height\_constant** to change the height of each row.
{% endhint %}

```text
data_matrix = [['Name', 'Equation'],
['Pythagorean Theorem', '$a^{2}+b^{2}=c^{2}$'],
['Euler\'s Formula', '$F-E+V=2$'],
['The Origin of Complex Numbers', '$i^{2}=-1$'],
['Einstein\'s Theory of Relativity', '$E=m c^{2}$']]
fig = ff.create_table(data_matrix,height_constant=40)
fig.show()
```

![](../../.gitbook/assets/newplot-2-%20%281%29.png)

### 5. Customized Table

{% hint style="info" %}
**`colorscale` for the table :**

* value 0 is the header color
* .5 is the first table color
* 1 is the second table color
{% endhint %}

```text
# load dataset and sample it
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/diabetes.csv')
df_sample = df[100: 110]
colorscale = [[0, '#0080ff'],[.5, 'silver'],[1, '#ffffff']]
fig = ff.create_table(df_sample, colorscale=colorscale)
fig.show()
```

![](../../.gitbook/assets/newplot-3-%20%282%29.png)

{% hint style="info" %}
* Customize font size
* Customize height of each row.
* Address index in the table
{% endhint %}

```text
data_matrix = [['Name', 'Equation'],
['Pythagorean Theorem', '$a^{2}+b^{2}=c^{2}$'],
['Euler\'s Formula', '$F-E+V=2$'],
['The Origin of Complex Numbers', '$i^{2}=-1$'],
['Einstein\'s Theory of Relativity', '$E=m c^{2}$']]
fig = ff.create_table(data_matrix,height_constant=40,index=True)
# Make text size larger
for i in range(len(fig.layout.annotations)):
fig.layout.annotations[i].font.size = 16
fig.show()
```

![](../../.gitbook/assets/newplot-4-%20%281%29.png)

45 changes: 45 additions & 0 deletions plotly/6.3-statistical-charts/6.3.2-tree-charts.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# 6.3.2 Dendrograms

The dendrogram is a tree diagram used to visualize and classify taxonomic relationships frequently used to illustrate the arrangement of the clusters produced by hierarchical clustering. The name dendrogram derives from the two ancient Greek words déndron and grámma, meaning “tree” and “drawing”. Dendrograms are frequently used in biology to show clustering between genes or samples, but they can represent any type of grouped data, i.e., used to illustrate the clustering of genes or samples.

The dendrogram consists of stacked branches \(called clades\) that break down into further smaller branches. At the lowest level will be individual elements and then they are grouped according to attributes into clusters with fewer and fewer clusters on higher levels. The end of each clade \(called a leaf\) is the data.

The arrangement of the clades reveals how similar they are to each other; two leaves in the same clade are more similar than two leaves in another clade. The y-axis \(the height of the branch\) shows how close data points or clusters are from one another. The taller the branch, the further and more different the clusters are.

![](../../.gitbook/assets/dendrogram-explained.png)

### 1. Basic Dendrogram

```text
import plotly.figure_factory as ff
import numpy as np
np.random.seed(1)
X = np.random.rand(10, 7) # 10 samples, with 7 dimensions each
fig = ff.create_dendrogram(X)
fig.update_layout(width=800, height=400)
fig.show()
```

![](../../.gitbook/assets/screenshot-2020-07-26-at-20.48.42.png)

### 2. Dendrogram with color threshold

```text
fig = ff.create_dendrogram(X, color_threshold=1)
fig.update_layout(width=800, height=500)
fig.show()
```

![](../../.gitbook/assets/screenshot-2020-07-26-at-20.48.58.png)

### 3. Categorical Dendrogram

```text
labels = ['A','B','C','D','E','F','G','H','I','J']
fig = ff.create_dendrogram(X, orientation='left', labels=labels)
fig.update_layout(width=800, height=800)
fig.show()
```

![](../../.gitbook/assets/screenshot-2020-07-26-at-20.49.06.png)

0 comments on commit bb328e8

Please sign in to comment.