In continuation of Generalize the configuration of axes · Issue #4042 · bokeh/bokeh · GitHub .
I’ve tried to follow Bryan’s second suggestion - to create the figure
without default axes:
import pandas as pd
from bokeh.io import gridplot, output_file, show
from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d
output_file(“test.html”)
df = pd.DataFrame()
df[‘time’] = [1, 2, 3, 4, 5]
df[‘temperature’] = [30, 31, 32.5, 33, 31]
df[‘humidity’] = [10, 30, 50, 20, 40]
df[‘sensor’] = [0.22, 0.12, 0.14, 0.08, 0.04]
---------- Doesn’t work -----------
s1 = figure(title=None, x_axis_location=None, y_axis_location=None)
s1 = figure(title=None, y_axis_location=None)
s1 = figure(title=None, x_axis_location=None)
-------------- Works --------------
s1 = figure(title=None)
-----------------------------------
s1.extra_x_ranges[‘time’] = Range1d(-1, 6)
s1.extra_y_ranges[‘temperature’] = Range1d(25, 35)
s1.extra_y_ranges[‘humidity’] = Range1d(0, 50)
s1.extra_y_ranges[‘sensor’] = Range1d(0, 0.25)
s1.extra_x_ranges = {
‘time’: Range1d(start=-1, end=6),
}
s1.extra_y_ranges = {
‘temperature’: Range1d(start=25, end=35),
‘humidity’: Range1d(start=0, end=50),
‘sensor’: Range1d(start=0, end=0.25),
}
s1.line(x=df[‘time’], y=df[‘temperature’],
x_range_name='time', y_range_name='temperature',
color='orange', legend='temperature')
s1.line(x=df[‘time’], y=df[‘humidity’],
x_range_name='time', y_range_name="humidity",
color="blue", alpha=0.5, legend='humidity')
s1.line(x=df[‘time’], y=df[‘sensor’],
x_range_name='time', y_range_name="sensor",
color="red", legend='sensory data')
s1.add_layout(LinearAxis(x_range_name=‘time’, axis_label=‘Time’), ‘below’)
s1.add_layout(LinearAxis(y_range_name=‘temperature’, axis_label=‘Temperature’), ‘left’)
s1.add_layout(LinearAxis(y_range_name=‘humidity’, axis_label=‘Humidity’), ‘left’)
s1.add_layout(LinearAxis(y_range_name=‘sensor’, axis_label=‘Sensor’), ‘right’)
show(s1)
``
This code generates the .html file, but instead of full plot I get only toolbar (zoom, reset, etc). With -- Works --
uncommented everything is generated fine, but the redundant base axes are also presented.
I’ve discovered some initialization code in bokeh/figure.py at branch-3.0 · bokeh/bokeh · GitHub which is called for base axes only, but cannot find out where could be the difference, which prevents the figure from being presented.
Does anyone have any ideas?