Skip to content

Commit 6f7ab71

Browse files
Convert more (#95)
1 parent 1d5b9af commit 6f7ab71

18 files changed

+809
-1523
lines changed

python/2D-Histogram.md

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
notebook_metadata_filter: all
5+
text_representation:
6+
extension: .md
7+
format_name: markdown
8+
format_version: '1.1'
9+
jupytext_version: 1.1.1
10+
kernelspec:
11+
display_name: Python 3
12+
language: python
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.6.7
24+
plotly:
25+
description: How to make 2D Histograms in Python with Plotly.
26+
display_as: statistical
27+
has_thumbnail: true
28+
ipynb: ~notebook_demo/24
29+
language: python
30+
layout: user-guide
31+
name: 2D Histograms
32+
order: 6
33+
page_type: u-guide
34+
permalink: python/2D-Histogram/
35+
thumbnail: thumbnail/histogram2d.jpg
36+
title: Python 2D Histograms | plotly
37+
---
38+
39+
### 2D Histogram of a Bivariate Normal Distribution ###
40+
41+
```python
42+
import plotly.graph_objects as go
43+
44+
import numpy as np
45+
46+
x = np.random.randn(500)
47+
y = np.random.randn(500)+1
48+
49+
fig = go.Figure(go.Histogram2d(
50+
x=x,
51+
y=y
52+
))
53+
fig.show()
54+
```
55+
56+
### 2D Histogram Binning and Styling Options ###
57+
58+
```python
59+
import plotly.graph_objects as go
60+
61+
import numpy as np
62+
63+
x = np.random.randn(500)
64+
y = np.random.randn(500)+1
65+
66+
fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability',
67+
autobinx=False,
68+
xbins=dict(start=-3, end=3, size=0.1),
69+
autobiny=False,
70+
ybins=dict(start=-2.5, end=4, size=0.1),
71+
colorscale=[[0, 'rgb(12,51,131)'], [0.25, 'rgb(10,136,186)'], [0.5, 'rgb(242,211,56)'], [0.75, 'rgb(242,143,56)'], [1, 'rgb(217,30,30)']]
72+
))
73+
fig.show()
74+
```
75+
76+
### 2D Histogram Overlaid with a Scatter Chart ###
77+
78+
```python
79+
import plotly.graph_objects as go
80+
81+
import numpy as np
82+
83+
x0 = np.random.randn(100)/5. + 0.5 # 5. enforces float division
84+
y0 = np.random.randn(100)/5. + 0.5
85+
x1 = np.random.rand(50)
86+
y1 = np.random.rand(50) + 1.0
87+
88+
x = np.concatenate([x0, x1])
89+
y = np.concatenate([y0, y1])
90+
91+
fig = go.Figure()
92+
93+
fig.add_trace(go.Scatter(
94+
x=x0,
95+
y=y0,
96+
mode='markers',
97+
showlegend=False,
98+
marker=dict(
99+
symbol='x',
100+
opacity=0.7,
101+
color='white',
102+
size=8,
103+
line=dict(width=1),
104+
)
105+
))
106+
fig.add_trace(go.Scatter(
107+
x=x1,
108+
y=y1,
109+
mode='markers',
110+
showlegend=False,
111+
marker=dict(
112+
symbol='circle',
113+
opacity=0.7,
114+
color='white',
115+
size=8,
116+
line=dict(width=1),
117+
)
118+
))
119+
fig.add_trace(go.Histogram2d(
120+
x=x,
121+
y=y,
122+
colorscale='YlGnBu',
123+
zmax=10,
124+
nbinsx=14,
125+
nbinsy=14,
126+
zauto=False,
127+
))
128+
129+
fig.update_layout(
130+
xaxis=dict( ticks='', showgrid=False, zeroline=False, nticks=20 ),
131+
yaxis=dict( ticks='', showgrid=False, zeroline=False, nticks=20 ),
132+
autosize=False,
133+
height=550,
134+
width=550,
135+
hovermode='closest',
136+
137+
)
138+
139+
fig.show()
140+
```
141+
142+
#### Reference
143+
See https://plot.ly/python/reference/#histogram2d for more information and chart attribute options!
144+

unconverted/python/2d-histogram-contour.md renamed to python/2d-histogram-contour.md

+36-73
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ jupyter:
88
format_version: '1.1'
99
jupytext_version: 1.1.1
1010
kernelspec:
11-
display_name: Python 2
11+
display_name: Python 3
1212
language: python
13-
name: python2
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.6.7
1424
plotly:
1525
description: How to make 2D Histogram Contour plots in Python with Plotly.
1626
display_as: statistical
@@ -26,71 +36,54 @@ jupyter:
2636
title: 2D Histogram Contour | Plotly
2737
---
2838

29-
#### New to Plotly?
30-
Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).
31-
<br>You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).
32-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
33-
34-
35-
#### Version Check
36-
Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.
37-
38-
```python
39-
import plotly
40-
plotly.__version__
41-
```
42-
4339
#### Basic 2D Histogram Contour
4440

4541
```python
46-
import plotly.plotly as py
47-
import plotly.graph_objs as go
42+
import plotly.graph_objects as go
4843

4944
import numpy as np
5045

5146
x = np.random.uniform(-1, 1, size=500)
5247
y = np.random.uniform(-1, 1, size=500)
5348

54-
trace = [go.Histogram2dContour(
49+
fig = go.Figure(go.Histogram2dContour(
5550
x = x,
5651
y = y
57-
)]
52+
))
5853

59-
py.iplot(trace, filename = "Basic Histogram2dContour")
54+
fig.show()
6055
```
6156

6257
#### 2D Histogram Contour Colorscale
6358

6459
```python
65-
import plotly.plotly as py
66-
import plotly.graph_objs as go
60+
import plotly.graph_objects as go
6761

6862
import numpy as np
6963

7064
x = np.random.uniform(-1, 1, size=500)
7165
y = np.random.uniform(-1, 1, size=500)
7266

73-
trace = [go.Histogram2dContour(
67+
fig = go.Figure(go.Histogram2dContour(
7468
x = x,
7569
y = y,
7670
colorscale = 'Blues'
77-
)]
71+
))
7872

79-
py.iplot(trace, filename = "Histogram2dContour Colorscale")
73+
fig.show()
8074
```
8175

8276
#### 2D Histogram Contour Styled
8377

8478
```python
85-
import plotly.plotly as py
86-
import plotly.graph_objs as go
79+
import plotly.graph_objects as go
8780

8881
import numpy as np
8982

9083
x = np.random.uniform(-1, 1, size=500)
9184
y = np.random.uniform(-1, 1, size=500)
9285

93-
trace = [go.Histogram2dContour(
86+
fig = go.Figure(go.Histogram2dContour(
9487
x = x,
9588
y = y,
9689
colorscale = 'Jet',
@@ -110,33 +103,32 @@ trace = [go.Histogram2dContour(
110103
)
111104
)
112105

113-
)]
106+
))
114107

115-
py.iplot(trace, filename = "Histogram2dContour Styled")
108+
fig.show()
116109
```
117110

118111
#### 2D Histogram Contour Subplot
119112

120113
```python
121-
import plotly.plotly as py
122-
import plotly.graph_objs as go
114+
import plotly.graph_objects as go
123115

124116
import numpy as np
125117

126118
t = np.linspace(-1, 1.2, 2000)
127119
x = (t**3) + (0.3 * np.random.randn(2000))
128120
y = (t**6) + (0.3 * np.random.randn(2000))
129121

130-
data = [
131-
go.Histogram2dContour(
122+
fig = go.Figure()
123+
fig.add_trace(go.Histogram2dContour(
132124
x = x,
133125
y = y,
134126
colorscale = 'Blues',
135127
reversescale = True,
136128
xaxis = 'x',
137129
yaxis = 'y'
138-
),
139-
go.Scatter(
130+
))
131+
fig.add_trace(go.Scatter(
140132
x = x,
141133
y = y,
142134
xaxis = 'x',
@@ -146,24 +138,23 @@ data = [
146138
color = 'rgba(0,0,0,0.3)',
147139
size = 3
148140
)
149-
),
150-
go.Histogram(
141+
))
142+
fig.add_trace(go.Histogram(
151143
y = y,
152144
xaxis = 'x2',
153145
marker = dict(
154146
color = 'rgba(0,0,0,1)'
155147
)
156-
),
157-
go.Histogram(
148+
))
149+
fig.add_trace(go.Histogram(
158150
x = x,
159151
yaxis = 'y2',
160152
marker = dict(
161153
color = 'rgba(0,0,0,1)'
162154
)
163-
)
164-
]
155+
))
165156

166-
layout = go.Layout(
157+
fig.update_layout(
167158
autosize = False,
168159
xaxis = dict(
169160
zeroline = False,
@@ -192,36 +183,8 @@ layout = go.Layout(
192183
showlegend = False
193184
)
194185

195-
196-
197-
fig = go.Figure(data=data,layout=layout)
198-
py.iplot(fig, filename='Histogram2dContour Subplot')
186+
fig.show()
199187
```
200188

201189
#### Reference
202190
See https://plot.ly/python/reference/#histogram2dcontour for more information and chart attribute options!
203-
204-
```python
205-
from IPython.display import display, HTML
206-
207-
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
208-
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
209-
210-
! pip install git+https://github.com/plotly/publisher.git --upgrade
211-
import publisher
212-
publisher.publish(
213-
'histogram2dcontour.ipynb', 'python/2d-histogram-contour/', '2D Histogram Contour',
214-
'How to make 2D Histogram Contour plots in Python with Plotly.',
215-
title = '2D Histogram Contour | Plotly',
216-
has_thumbnail='true', thumbnail='thumbnail/hist2dcontour.png',
217-
language='python',
218-
# page_type='example_index', // note this is only if you want the tutorial to appear on the main page: plot.ly/python
219-
display_as='statistical',
220-
order=30,
221-
ipynb='~notebook_demo/199',
222-
uses_plotly_offline=False)
223-
```
224-
225-
```python
226-
227-
```

0 commit comments

Comments
 (0)