Skip to content

Commit 5705af6

Browse files
author
Joseph Damiba
committed
add examples from wishlish
1 parent a8a952d commit 5705af6

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

Diff for: doc/python/3d-surface-plots.md

+13
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ fig = go.Figure(data=[
163163
fig.show()
164164
```
165165

166+
### Setting the Surface Color
167+
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+
170+
```python
171+
import plotly.graph_objects as go
172+
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))
176+
fig.show()
177+
```
178+
166179
#### Reference
167180

168181

Diff for: doc/python/bar-charts.md

+20
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,26 @@ fig.show()
384384

385385
See examples of horizontal bar charts [here](https://plotly.com/python/horizontal-bar-charts/).
386386

387+
### Bar Charts With Multicategory Axis Type
388+
389+
If your traces have arrays for `x` or `y`, then the axis type is automatically inferred to be `multicategory`.
390+
391+
```python
392+
import plotly.graph_objects as go
393+
x = [
394+
["BB+", "BB+", "BB+", "BB", "BB", "BB"],
395+
[16, 17, 18, 16, 17, 18,]
396+
]
397+
fig = go.Figure()
398+
fig.add_bar(x=x,y=[1,2,3,4,5,6])
399+
fig.add_bar(x=x,y=[6,5,4,3,2,1])
400+
fig.update_layout(barmode="relative")
401+
fig.show()
402+
```
403+
404+
405+
406+
387407
### Reference
388408

389409
See https://plotly.com/python/reference/#bar for more information and chart attribute options!

Diff for: doc/python/box-plots.md

+9
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,15 @@ fig.update_layout(
489489
fig.show()
490490
```
491491

492+
### Box Plot With Only Points
493+
494+
```python
495+
import plotly.express as px
496+
df = px.data.tips()
497+
fig = px.strip(df, x='day', y='tip')
498+
fig.show()
499+
```
500+
492501
#### Reference
493502

494503
See https://plotly.com/python/reference/#box for more information and chart attribute options!

Diff for: doc/python/line-and-scatter.md

+19
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,25 @@ 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+
277296
### Reference
278297

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

Diff for: doc/python/line-charts.md

+14
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ fig = px.line(df, x="year", y="lifeExp", color="continent",
7070
fig.show()
7171
```
7272

73+
### Sparklines with Plotly Express
74+
75+
Sparklines are scatter plots inside subplots, with gridlines, axis lines, and ticks removed.
76+
77+
```python
78+
import plotly.express as px
79+
df = px.data.gapminder().query("continent == 'Oceania'")
80+
fig = px.line(df, x='year', y='gdpPercap', facet_row='country')
81+
fig.update_layout(template=None, height=400)
82+
fig.update_xaxes(showgrid=False)
83+
fig.update_yaxes(showgrid=False)
84+
fig.show()
85+
```
86+
7387
### Line Plot with go.Scatter
7488

7589
If Plotly Express does not provide a good starting point, it is possible to use the more generic `go.Scatter` function from `plotly.graph_objects`. Whereas `plotly.express` has two functions `scatter` and `line`, `go.Scatter` can be used both for plotting points (makers) or lines, depending on the value of `mode`. The different options of `go.Scatter` are documented in its [reference page](https://plotly.com/python/reference/#scatter).

Diff for: doc/python/sliders.md

+48
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,54 @@ The method determines which [plotly.js function](https://plot.ly/javascript/plot
8888
- `"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+
138+
91139
### Sliders in Plotly Express
92140
Plotly Express provide sliders, but with implicit animation. The animation can be ommited by removing `updatemenus` in the `layout`:
93141

Diff for: doc/python/violin.md

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ fig.update_layout(xaxis_showgrid=False, xaxis_zeroline=False)
258258
fig.show()
259259
```
260260

261+
### Violin Plot With Only Points
262+
263+
See https://plotly.com/python/box-plots/#box-plot-with-only-points.
264+
261265
#### Reference
262266

263267
See https://plotly.com/python/reference/#violin for more information and chart attribute options!

0 commit comments

Comments
 (0)