Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2e7667

Browse files
tweaks
1 parent 47b6c5d commit d2e7667

File tree

7 files changed

+59
-149
lines changed

7 files changed

+59
-149
lines changed

doc/python/3d-surface-coloring.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

doc/python/3d-surface-plots.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jupyter:
3030
order: 3
3131
page_type: example_index
3232
permalink: python/3d-surface-plots/
33+
redirect_from: python/3d-surface-coloring/
3334
thumbnail: thumbnail/3d-surface.jpg
3435
---
3536

@@ -54,7 +55,7 @@ fig.show()
5455

5556
### Passing x and y data to 3D Surface Plot
5657

57-
If you do not specify `x` and `y` coordinates, integer indices are used for the `x` and `y` axis. You can also pass `x` and `y` values to `go.Surface`.
58+
If you do not specify `x` and `y` coordinates, integer indices are used for the `x` and `y` axis. You can also pass `x` and `y` values to `go.Surface`.
5859

5960
```python
6061
import plotly.graph_objects as go
@@ -98,7 +99,7 @@ fig.update_layout(title='Mt Bruno Elevation', autosize=False,
9899
fig.show()
99100
```
100101
#### Configure Surface Contour Levels
101-
This example shows how to slice the surface graph on the desired position for each of x, y and z axis. [contours.x.start](https://plotly.com/python/reference/#surface-contours-x-start) sets the starting contour level value, `end` sets the end of it, and `size` sets the step between each contour level.
102+
This example shows how to slice the surface graph on the desired position for each of x, y and z axis. [contours.x.start](https://plotly.com/python/reference/#surface-contours-x-start) sets the starting contour level value, `end` sets the end of it, and `size` sets the step between each contour level.
102103

103104
```python
104105
import plotly.graph_objects as go
@@ -165,18 +166,34 @@ fig.show()
165166

166167
### Setting the Surface Color
167168

168-
You can use the `surfacecolor` attribute to define the color of the surface of your figure. In this example, the surface color is drawn relation to the x-axis data.
169+
You can use the `surfacecolor` attribute to define the color of the surface of your figure. In this example, the surface color represents the distance from the origin, rather than the default, which is the `z` value.
169170

170171
```python
171172
import plotly.graph_objects as go
173+
from plotly.subplots import make_subplots
174+
175+
# Equation of ring cyclide
176+
# see https://en.wikipedia.org/wiki/Dupin_cyclide
172177
import numpy as np
173-
x, y = 4 * np.pi * np.mgrid[0:1:20j, 0:1:20j]
174-
z = np.sin(x)
175-
fig = go.Figure(go.Surface(x=x, y=y, z=z, surfacecolor=x))
178+
a, b, d = 1.32, 1., 0.8
179+
c = a**2 - b**2
180+
u, v = np.mgrid[0:2*np.pi:100j, 0:2*np.pi:100j]
181+
x = (d * (c - a * np.cos(u) * np.cos(v)) + b**2 * np.cos(u)) / (a - c * np.cos(u) * np.cos(v))
182+
y = b * np.sin(u) * (a - d*np.cos(v)) / (a - c * np.cos(u) * np.cos(v))
183+
z = b * np.sin(v) * (c*np.cos(u) - d) / (a - c * np.cos(u) * np.cos(v))
184+
185+
fig = make_subplots(rows=1, cols=2,
186+
specs=[[{'is_3d': True}, {'is_3d': True}]],
187+
subplot_titles=['Color corresponds to z', 'Color corresponds to distance to origin'],
188+
)
189+
190+
fig.add_trace(go.Surface(x=x, y=y, z=z, colorbar_x=-0.07), 1, 1)
191+
fig.add_trace(go.Surface(x=x, y=y, z=z, surfacecolor=x**2 + y**2 + z**2), 1, 2)
192+
fig.update_layout(title_text="Ring cyclide")
176193
fig.show()
177194
```
178195

179196
#### Reference
180197

181198

182-
See https://plotly.com/python/reference/#surface for more information!
199+
See https://plotly.com/python/reference/#surface for more information!

doc/python/box-plots.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ fig.show()
491491

492492
### Box Plot With Only Points
493493

494+
A [strip chart](/python/strip-charts/) is like a box plot with points showing, and no box:
495+
494496
```python
495497
import plotly.express as px
496498
df = px.data.tips()
@@ -500,4 +502,4 @@ fig.show()
500502

501503
#### Reference
502504

503-
See https://plotly.com/python/reference/#box for more information and chart attribute options!
505+
See https://plotly.com/python/reference/#box for more information and chart attribute options!

doc/python/line-and-scatter.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,6 @@ fig = go.Figure(data=go.Scattergl(
274274
fig.show()
275275
```
276276

277-
### Sparklines With go.Scatter
278-
279-
Sparklines are scatter plots inside subplots, with gridlines, axis lines, and ticks removed.
280-
281-
```python
282-
import plotly.express as px
283-
from plotly.subplots import make_subplots
284-
df = px.data.gapminder()
285-
fig = make_subplots(2, 1)
286-
df1 = df.query("country == 'Canada'")
287-
fig.add_trace(go.Scatter(x=df1['year'], y=df1['gdpPercap'], mode='lines', name='Canada'), 1, 1)
288-
df2 = df.query("country == 'France'")
289-
fig.add_trace(go.Scatter(x=df2['year'], y=df2['gdpPercap'], mode='lines', name='France'), 2, 1)
290-
fig.update_layout(template=None, height=400)
291-
fig.update_xaxes(showgrid=False)
292-
fig.update_yaxes(showgrid=False)
293-
fig.show()
294-
```
295-
296277
### Reference
297278

298279
See https://plotly.com/python/reference/#scatter or https://plotly.com/python/reference/#scattergl for more information and chart attribute options!

doc/python/line-charts.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,29 @@ fig.show()
7171

7272
### Sparklines with Plotly Express
7373

74-
Sparklines are scatter plots inside subplots, with gridlines, axis lines, and ticks removed.
74+
Sparklines are scatter plots inside subplots, with gridlines, axis lines, and ticks removed.
7575

7676
```python
7777
import plotly.express as px
78-
df = px.data.gapminder().query("continent == 'Oceania'")
79-
fig = px.line(df, x='year', y='gdpPercap', facet_row='country')
80-
fig.update_layout(template=None, height=400)
81-
fig.update_xaxes(showgrid=False)
82-
fig.update_yaxes(showgrid=False)
83-
fig.show()
78+
df = px.data.stocks(indexed=True)
79+
fig = px.line(df, facet_row="company", facet_row_spacing=0.01, height=200, width=200)
80+
81+
# hide and lock down axes
82+
fig.update_xaxes(visible=False, fixedrange=True)
83+
fig.update_yaxes(visible=False, fixedrange=True)
84+
85+
# remove facet/subplot labels
86+
fig.update_layout(annotations=[], overwrite=True)
87+
88+
# strip down the rest of the plot
89+
fig.update_layout(
90+
showlegend=False,
91+
plot_bgcolor="white",
92+
margin=dict(t=10,l=10,b=10,r=10)
93+
)
94+
95+
# disable the modebar for such a small plot
96+
fig.show(config=dict(displayModeBar=False))
8497
```
8598

8699
### Line Plot with go.Scatter
@@ -421,4 +434,4 @@ fig.show()
421434

422435
#### Reference
423436

424-
See https://plotly.com/python/reference/#scatter for more information and chart attribute options!
437+
See https://plotly.com/python/reference/#scatter for more information and chart attribute options!

doc/python/sliders.md

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jupyter:
3434
---
3535

3636
### Simple Slider Control
37-
Sliders can be used in Plotly to change the data displayed or style of a plot.
37+
Sliders can be used in Plotly to change the data displayed or style of a plot.
3838

3939
```python
4040
import plotly.graph_objects as go
@@ -83,61 +83,14 @@ fig.show()
8383

8484
#### Methods
8585
The method determines which [plotly.js function](https://plot.ly/javascript/plotlyjs-function-reference/) will be used to update the chart. Plotly can use several [updatemenu](https://plot.ly/python/reference/#layout-updatemenus-items-updatemenu-buttons-items-button-method) methods to add the slider:
86+
- `"update"`: modify **data and layout** attributes (as above)
8687
- `"restyle"`: modify **data** attributes
8788
- `"relayout"`: modify **layout** attributes
88-
- `"update"`: modify **data and layout** attributes
8989
- `"animate"`: start or pause an animation
9090

91-
### Update Slider
92-
```python
93-
import plotly.graph_objects as go
94-
import numpy as np
95-
96-
# Create figure
97-
fig = go.Figure()
98-
99-
# Add traces, one for each slider step
100-
for step in np.arange(0, 5, 0.1):
101-
fig.add_trace(
102-
go.Scatter(
103-
visible=False,
104-
line=dict(color="#00CED1", width=6),
105-
name="𝜈 = " + str(step),
106-
x=np.arange(0, 10, 0.01),
107-
y=np.sin(step * np.arange(0, 10, 0.01))))
108-
109-
# Make 10th trace visible
110-
fig.data[10].visible = True
111-
112-
# Create and add slider
113-
steps = []
114-
for i in range(len(fig.data)):
115-
step = dict(
116-
method="update",
117-
args=[{"visible":[False] * len(fig.data)}, # update for traces
118-
{"title":str(i)} # update for layout
119-
],
120-
)
121-
step["args"][0]["visible"][i] = True # Toggle i'th trace to "visible"
122-
steps.append(step)
123-
124-
sliders = [dict(
125-
active=10,
126-
currentvalue={"prefix": "Frequency: "},
127-
pad={"t": 50},
128-
steps=steps
129-
)]
130-
131-
fig.update_layout(
132-
sliders=sliders
133-
)
134-
135-
fig.show()
136-
```
137-
13891

13992
### Sliders in Plotly Express
140-
Plotly Express provide sliders, but with implicit animation. The animation can be ommited by removing `updatemenus` in the `layout`:
93+
Plotly Express provide sliders, but with implicit animation using the `"animate"` method described above. The animation play button can be ommited by removing `updatemenus` in the `layout`:
14194

14295
```python
14396
import plotly.express as px

doc/python/violin.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@ fig.show()
262262

263263
### Violin Plot With Only Points
264264

265-
See https://plotly.com/python/box-plots/#box-plot-with-only-points.
265+
A [strip chart](/python/strip-charts/) is like a violin plot with points showing, and no violin:
266+
267+
```python
268+
import plotly.express as px
269+
df = px.data.tips()
270+
fig = px.strip(df, x='day', y='tip')
271+
fig.show()
272+
```
266273

267274
#### Reference
268275

0 commit comments

Comments
 (0)