[BUG?] Legend goes crazy if plotting more than 24 Vertical Lines?
See original GitHub issueI’m pasting here full code for reproducibility. Please jump to bottom section Problem Description and Questions
first, if you wish.
# Versions
bokeh==0.12.13 holoviews==1.9.2 pandas==0.22.0
Imports
import numpy as np
import pandas as pd
import datetime
import random
import holoviews as hv
hv.extension('bokeh')
Generation and plotting functions
#generate dummy df
def generate_df(size):
d = {
'dates':
pd.date_range('1980-01-01', periods=size, freq='1T'),
'signal1':
np.random.normal(0, 0.3, size=size).cumsum() + 50,
'signal2':
np.random.normal(0, 0.3, size=size).cumsum() + 50,
'signal3':
np.random.normal(0, 0.3, size=size).cumsum() + 50
}
df = pd.DataFrame(d)
return df.melt(id_vars='dates').sort_values('dates')
#generate dummy dates
def generate_random_date(begin, end):
diff = end - begin
return begin + datetime.timedelta(seconds=random.randint(0, int(diff.total_seconds())))
def generate_random_dates(begin, end, n):
return [generate_random_date(begin, end) for i in range(0,n)]
#plot a timeseries
def plot_timeseries(df, width=800, height=400, title='plot', legend_position='top_right'):
plot_opts=dict()
plot_opts['show_grid'] = True
plot_opts['width'] = width
plot_opts['height'] = height
plot_opts['legend_position'] = legend_position
plot_opts['legend_limit'] = 1000
curve_1 = hv.Curve( df,
kdims=['dates'],
vdims=['value', 'variable'],
label=title).groupby('variable')
return curve_1.overlay().opts(plot=plot_opts)
#Overlay a list of vertical lines
def vertical_lines(vlines_list):
plot_opts=dict()
plot_opts['show_legend'] = False
plot_opts['show_title'] = False
style_opts = dict()
style_opts['line_color'] = 'brown'
style_opts['linewidth'] = '4'
vlines = []
for line in vlines_list:
vlines.append(hv.VLine(line)(plot=plot_opts,
style=style_opts))
return hv.Overlay(vlines)
Generate df and dates and plot them
small_df = generate_df(10000)
small_df.head()
<div>
dates | variable | value | |
---|---|---|---|
0 | 1980-01-01 00:00:00 | signal1 | 49.800754 |
20000 | 1980-01-01 00:00:00 | signal3 | 50.292620 |
10000 | 1980-01-01 00:00:00 | signal2 | 50.425544 |
1 | 1980-01-01 00:01:00 | signal1 | 49.896840 |
20001 | 1980-01-01 00:01:00 | signal3 | 50.497810 |
With 24 lines
vlines_list = generate_random_dates(small_df.dates.min(), small_df.dates.max(), 24)
vertical_lines(vlines_list) * plot_timeseries(small_df, title='24 lines')
With 25 lines
vlines_list = generate_random_dates(small_df.dates.min(), small_df.dates.max(), 25)
vertical_lines(vlines_list) * plot_timeseries(small_df, title='25 lines')
Problem Description and Questions
I am overlaying a Curves Overlay (function plot_timeseries
) with many vertical lines (function vertical_lines
).
If I generate and plot 24 vertical lines the legend appears correctly (see legend of figure section With 24 lines
).
If I generate and plot 25 vertical lines the legend appears incorrectly (see legend of figure section With 25 lines
).
Questions:
- Is this a bug?
- Or am I doing something wrong? For instance, is there a more efficient way of plotting several vertical lines besides calling VLine repeatedly? Such as, sending a list as argument.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Vertical line artefacts in 2D lineplot - python - Stack Overflow
It seems that in your data some points have the same x values. line_plot will see them as a single point with different...
Read more >plotrix: Various Plotting Functions
Whether to draw vertical lines between each column of the table. ... to get this wrong. As a 'barNest' plot with more than...
Read more >Stereonet 11 | Rick Allmendinger's Stuff
Fixed a bug related to exporting SVG plots of rose diagrams based on trends of lines (Thanks, Derek!) SVG output of rose diagrams...
Read more >Visualize summary statistics with box plot - MATLAB boxplot
Create a Box Plot The boxplot shows that the median miles per gallon for all vehicles in the sample data is approximately 24....
Read more >4 Drawing charts and graphs
If there is more than one line on the graph, there will also need to be a legend or key to show what...
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
Legends are limited to 25 entries by default because things often getting messy otherwise. Since VLine does not actually have a legend entry it shouldn’t count toward this limit but seemingly it does, so I’ll leave this open. For now you raise the limit with:
overlay.opts(plot=dict(legend_limit=50))
or do so globally:
Probably not, deserves a little note in the VLine/HLine reference notebooks for bokeh (and maybe matplotlib too) as I’m not sure axvline/axhline participate in legends there either.