Negative values are not showing with circle function in extra_y_ranges

Negative values are not showing with the circle function in extra_y_ranges

import pandas as pd
from bokeh.plotting import figure, output_file, show
# create a new plot with a datetime axis type

station = 'lena'
p = figure(width=600, height=250, y_axis_type="auto",x_axis_label = "Month", y_axis_label='m/mon')
# p.title.text = 'GRO Observation data  vs.  VIC River Routing Model data '
p.title.text = station

# p.line(cru_tmp_seasonality['mon'], cru_tmp_seasonality['yukon'], color='tomato', alpha=0.8,line_width=3,legend_label='temp.')

tmp_min = cru_tmp_seasonality[station].min()
tmp_max = cru_tmp_seasonality[station].max()

p.extra_y_ranges = {"Temp": Range1d(start=tmp_min-5, end=tmp_max+5)}
linaxis = LinearAxis(axis_label='Temp', y_range_name='Temp')
p.add_layout(linaxis, 'right')

p.line(vic_seasonality['mon'], vic_seasonality[station]*(155520000)/(2.45E+12), color='green', alpha=0.8, line_width=3,legend_label='VIC streamflow (MODEL)')
p.line(obs_seasonality['mon'], obs_seasonality[station]*(155520000)/(2.45E+12), color='orange', alpha=0.8, line_width=3,legend_label='GRO streamflow (OBS)')
p.line(cru_pre_seasonality['mon'], cru_pre_seasonality[station]/(10^4), color='steelblue', alpha=0.8, line_width=3,legend_label='CRU prep.')
p.line(cru_tmp_seasonality['mon'], cru_tmp_seasonality[station], color='tomato', alpha=0.8, line_width=3,legend_label='CRU temp.', y_range_name="Temp")['mon'], cru_tmp_seasonality[station], color='tomato',alpha=1, y_range_name="Temp")['mon'], cru_pre_seasonality[station]/(10^4), color='steelblue',alpha=1,)['mon'], obs_seasonality[station]*(155520000)/(2.45E+12), color='orange', alpha=1)['mon'], vic_seasonality[station]*(155520000)/(2.45E+12), color='green', alpha=1,)

p.xaxis.ticker = obs_seasonality['mon']
p.add_layout(p.legend[0], 'right')

@Yeonjin_Son We can’t really offer any help unless we can run some code that reproduces your issue to investigate directly. It’s especially impossible to speculate without any idea of what the actual data is. Please update your post to provide a complete Minimal Reproducible Example that has everything necessary to actually run. (And please pay attention to “minimal” and remove everything that is not directly related to or necessary to reproduce the problem/question)

I add the data so that you can run the code, but the D(Temp) should follow the right side second y-axis, now it’s not… please help me :frowning:

import pandas as pd
from bokeh.plotting import figure, output_file, show

station = 'kolyma'
A =  cru_pre_seasonality
B =  vic_seasonality
C =  obs_seasonality
D =  cru_tmp_seasonality

A['mon'] = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12])
B['mon'] = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12])
C['mon'] = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12])
D['mon'] = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12])

A[station] =pd.Series([13.818403,12.114834,10.897287,8.847852,15.092023,35.784438,51.629273,50.136718,30.828864,22.108417,20.815241,14.815963])
C['Kolyma_1']=pd.Series([400.720430, 356.284566, 330.132258, 305.548081,3239.307738,9300.190625,4455.306452,4249.901210,3890.114583,1567.707946,570.132258,471.486322])
D[station]=pd.Series([-35.181452,-32.864750,-25.335706,-13.432518,0.012718,9.364006, 11.648732,8.546146,1.876382,-10.683690,-25.358102,-33.358913])

p = figure(width=600, height=250, y_axis_type="auto",x_axis_label = "Month", y_axis_label='m/mon')
p.title.text = station
p.xaxis.ticker = A['mon']

tmp_min = D[station].min()
tmp_max = D[station].max()
p.extra_y_ranges = {"Temp": Range1d(start=tmp_min-5, end=tmp_max+5,)}
linaxis = LinearAxis(axis_label='Temp', y_range_name='Temp')
p.add_layout(linaxis, 'right')

p.line(A['mon'], A[station]/(10^4), color='steelblue', alpha=0.8, line_width=3,legend_label='CRU prep.')
p.line(B['mon'], B[station]*(155520000)/(652958000000), color='green', alpha=0.8, line_width=3,legend_label='VIC streamflow (MODEL)')
p.line(C['mon'], C['Kolyma_1']*(155520000)/(652958000000), color='orange', alpha=0.8, line_width=3,legend_label='GRO streamflow (OBS)')
p.line(D['mon'], D[station], color='tomato', alpha=0.8, line_width=3,legend_label='CRU temp.', y_range_name="Temp")['mon'], A[station]/(10^4), color='steelblue',alpha=1,)['mon'], B[station]*(155520000)/(652958000000), color='green', alpha=1,)['mon'], C['Kolyma_1']*(155520000)/(652958000000), color='orange', alpha=1,)['mon'], D[station], color='tomato',alpha=1, y_range_name="Temp")

p.add_layout(p.legend[0], 'right')

@Yeonjin_Son The example is still not complete, i.e. it is not runnable:

NameError: name 'cru_pre_seasonality' is not defined

At a glance, I am not really sure what you are expecting to be different? The outpout looks correct to me. The “D” data goes from about -35 to 11, the extra range is configured with those values +/-5, so about -40 to 16, and that is exactly what the range on the right shows.

Do you mean instead that you want the left range to be more compressed? The default range is an auto-range and by default it auto-ranges for all the glyphs in a plot. If you want to exclude the “D” renderer from that auto-ranging, then you need to explicitly set p.y_range.renderers to contain only glyph renderers that you want to be auto-ranged for that axis.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.