Plot legend shows value instead of text specified
See original GitHub issueOn a Plot legend (bokeh 0.12.3), if the name for the legend is the same as the name for the column in the data source, the value will be displayed int he legend instead of the name. Is this expected behavior?
Example:
from bokeh import plotting
from bokeh.models import ColumnDataSource, Range1d
from bokeh.io import curdoc, show
import pandas as pd
data = [{"right1": 10, "right2": 14, "right3": 17,
"right4": 22, "right5": 37, "right6": 44,
"right7": 49, "right8": 59}]
source = pd.DataFrame(data)
source = ColumnDataSource(source)
fig = plotting.figure(width=1200, height=900)
fig.hbar(y=1, right="right1", left=0, height=0.5, fill_color="blue", source=source, legend="right1")
fig.hbar(y=1, left="right1", right="right2", height=0.5, fill_color="green",
line_color="black", source=source, legend="right2")
fig.hbar(y=1, left="right2", right="right3", height=0.5, fill_color="yellow",
line_color="black", source=source, legend="right3")
fig.hbar(y=1, left="right3", right="right4", height=0.5, fill_color="orange",
line_color="black", source=source, legend="right4")
fig.hbar(
y=1, left="right4", right="right5", height=0.5, fill_color="red", line_color="black", source=source,
legend="right 5")
fig.hbar(
y=1, left="right5", right="right6", height=0.5, fill_color="purple", line_color="black", source=source,
legend="right 6")
fig.hbar(y=1, left="right6", right="right7", height=0.5,
fill_color="grey", line_color="black", source=source, legend="7.")
fig.hbar(
y=1, left="right7", right="right8", height=0.5, color="black", line_color="black", source=source, legend="*8.",
fill_alpha=.12, line_alpha=.12)
curdoc().add_root(fig)
show(fig)
As you can see, in the legend for the first 4 hbar(s), the value for that hbar is displayed instead of the text specified in legend=
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:17 (14 by maintainers)
Top Results From Across the Web
python - How do you just show the text label in plot legend ...
With a few extra lines the labels can have the same color as their line. just use .set_color() via legend.get_texts() . # Now...
Read more >Customizing Plot Legends | Python Data Science Handbook
Plot legends give meaning to a visualization, assigning meaning to the various plot ... (alpha value) of the frame, or change the padding...
Read more >Add a legend to a chart - Microsoft Support
Click the chart. next to the chart, and click Select Data. Select an entry in the Legend Entries (Series) list, and click Edit....
Read more >Legend guide — Matplotlib 3.6.2 documentation
For example, if you want your axes legend located at the figure's top right-hand corner instead of the axes' corner, simply specify the...
Read more >LEGEND Statement - SAS Help Center
If both are present, SAS/GRAPH uses the last one specified. ... output to display a long label text, the variable name is displayed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Rubyj Yes, this is a new feature that allows legends to be automatically generated by grouping values in a column data source for a single glyph. In conjunction with a categorical color mapper this can often greatly reduce code needed. If you don’t want this behaviour, there are two options:
legend
string valuelegend=dict(value="foo")
to the glyph functionping @birdsarah this is the second time today this question has come up. Perhaps we need better documentation support
The way to make this work is now:
because
bokeh.properties
has becomebokeh.core.properties
.I have to say, I’m a new bokeh user and this legend thing was a major speedbump that cost me about an hour. Couldn’t find the answer until I came across it here.