-
Notifications
You must be signed in to change notification settings - Fork 1
texttemplate.py tutorial #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4233260
texttemplate.py tutorial
fe30afb
few minor revision
51f5aef
revisions
088e19e
revision2
252ec10
moved texttemplate to text-and-annotations
5c17542
change formatting for texttemplate
921ca0b
minor revision
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
notebook_metadata_filter: all | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.1' | ||
jupytext_version: 1.2.1 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
language_info: | ||
codemirror_mode: | ||
name: ipython | ||
version: 3 | ||
file_extension: .py | ||
mimetype: text/x-python | ||
name: python | ||
nbconvert_exporter: python | ||
pygments_lexer: ipython3 | ||
version: 3.7.3 | ||
plotly: | ||
description: How to use text template in Python with Plotly. | ||
display_as: file_settings | ||
has_thumbnail: true | ||
ipynb: ~notebook_demo/252 | ||
language: python | ||
layout: base | ||
name: Text Template | ||
order: 40 | ||
page_type: u-guide | ||
permalink: python/texttemplate/ | ||
thumbnail: thumbnail/texttemplate.jpg | ||
title: Text Template and Formatting| plotly | ||
v4upgrade: true | ||
--- | ||
|
||
### Customize Displayed Text with a Text Template | ||
To show an arbitrary text in your chart you can use [texttemplate](https://plot.ly/python/reference/#pie-texttemplate), which is a template string used for rendering the information, and will override [textinfo](https://plot.ly/python/reference/#treemap-textinfo). | ||
This template string can include `variables` in %{variable} format, `numbers` in [d3-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_forma), and `date` in [d3-time-fomrat's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format). | ||
`texttemplate` customizes the text that appears on your plot vs. [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate) customize the tooltip text. | ||
|
||
emmanuelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Pie( | ||
values = [2, 5, 3, 2.5], | ||
labels = ["R", "Python", "Java Script", "Matlab"], | ||
texttemplate = "%{label}: %{value} (%{percent})", | ||
textposition = "inside")) | ||
|
||
fig.show() | ||
``` | ||
|
||
### Customize Text Template | ||
|
||
The following example uses [textfont](https://plot.ly/python/reference/#scatterternary-textfont) to customize the added text. | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Scatterternary( | ||
a = [3, 2, 5], | ||
b = [2, 5, 2], | ||
c = [5, 2, 2], | ||
mode = "markers+text", | ||
text = ["A", "B", "C"], | ||
texttemplate = "%{text}<br>(%{a:.2f}, %{b:.2f}, %{c:.2f})", | ||
textposition = "bottom center", | ||
textfont = {'family': "Times", 'size': [18, 21, 20], 'color': ["IndianRed", "MediumPurple", "DarkOrange"]} | ||
)) | ||
|
||
fig.show() | ||
``` | ||
### Set Date in Text Template | ||
The following example shows how to show date by setting [axis.type](https://plot.ly/python/reference/#layout-yaxis-type) in [funnel charts](https://plot.ly/python/funnel-charts/). | ||
|
||
```python | ||
from plotly import graph_objects as go | ||
|
||
fig = go.Figure() | ||
|
||
fig.add_trace(go.Funnel( | ||
name = 'Montreal', | ||
orientation = "h", | ||
y = ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], | ||
x = [100, 60, 40, 20], | ||
textposition = "inside", | ||
texttemplate = "%{label}")) | ||
|
||
fig.add_trace(go.Funnel( | ||
name = 'Vancouver', | ||
orientation = "h", | ||
y = ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], | ||
x = [90, 70, 50, 10], | ||
textposition = "inside", | ||
textinfo = "label")) | ||
emmanuelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.update_layout(yaxis = {'type': 'date'}) | ||
|
||
fig.show() | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hovertemplate customizeS