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
Let's now look at examples of adding labels using the `pyplot` API
### pyplot
The function for plotting labels in `pyplot` is [`plt.label`](../../api/pyplot.md#bqplot.pyplot.label). It takes three main arguments:
1. __text__ vector of text label values
2. __x__ vector of x values representing the x coordinates for the labels
3. __y__ vector of y values representing the y coordinates for the labels
For further customization, any of the attributes above can be passed as keyword args.
### Code Examples
#### Simple Label
```py
import numpy as np
import bqplot.pyplot as plt
fig = plt.figure(title="Basic Label Example")
x = np.linspace(0, 2 * np.pi)
y = np.sin(x)
line = plt.plot(x, y)
label = plt.label(
text=["Max", "Min"],
x=[.5 * np.pi, 1.5 * np.pi],
y=[1, -1]
)
fig
```

!!! tip
To render labels professionally it's better to offset the label to avoid obscuring the true graph below. To do so, set the `x_offset` and `y_offset` attrbiutes (which accepts values in pixels), like so:
```py
label.x_offset = 10
label.y_offset = 10
```
Attributes can also be updated in separate notebook cells or in callbacks when an event is triggered!
```py
# update the label color
label.colors = ['red', 'blue']
```
#### Figure Coordinates
Use the coordinates relative to the figure to more easily plot labels for important features.
```py
fig = plt.figure()
y = np.cumsum(np.random.randn(100))
line = plt.plot(np.arange(y.size), y_data)
label = plt.label(
["Halfway Point"],
default_size=26,
font_weight="bolder",
colors=["orange"]
)
label.x = [0.5]
label.y = [0.5]
```

Further, we can use values expressed in the units of the data. For example, if we consider a time series, we might want to label a specific date. Rather than calculating the position of the data with respect to the figure, we can simply pass in the date to the label function.
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
- Mark Interactions: usage/interactions/mark-interactions.md
- Selectors: usage/interactions/selectors.md
Expand Down
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.
Label Docs #1594
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
Uh oh!
There was an error while loading. Please reload this page.
Label Docs #1594
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing