Ich habe den folgenden Code geschrieben, um ein Liniendiagramm basierend auf Daten aus einem Pandas-Datenframe zu erstellen. Der Index des Datenrahmens ist eine Zeitreihe.Python Bokeh zusätzliche Y-Achse Probleme
Der folgende Code funktionierte gut, aber ich entschied, dass ich eine weitere Datenreihe hinzufügen wollte (aus der dritten Spalte in meinem Datenrahmen, im Code als 'Col3' bezeichnet). Ich wollte diese dritte Serie auf einer separaten Y-Achse haben. Als ich jedoch den Code dazu hinzugefügt habe, der unten durch den *** hervorgehoben ist, scheint Bokeh nicht in der Lage zu sein, eine Handlung zu produzieren. Hat jemand eine Ahnung was ich falsch mache?
from bokeh.plotting import figure, output_file, show, save
from bokeh.models import ColumnDataSource
from bokeh.models import Range1d, LinearAxis
import pandas as pd
from pandas import HDFStore
from bokeh.palettes import Spectral11
store = pd.HDFStore(<dataframe location>)
df = pd.DataFrame(store['d1'])
df = df.rename_axis('Time')
df.fillna(0)
numlines = len(df.columns)
#import colour pallete
mypalette = Spectral11[0:numlines]
# remove unwanted columns
col_list = ['Col1', 'Col2', 'Col3']
df = df[col_list]
# make a list of our columns
col = []
[col.append(i) for i in df.columns]
# make the figure,
p = figure(x_axis_type="datetime", title="<Plot Title>", width = 800, height = 450)
p.xaxis.axis_label = 'Date'
p.yaxis.axis_label = '<Name of Primary Y Axis>'
*** # add extra y axis
p.extra_y_ranges = {'Col3': Range1d(start=0, end=0.25)}
p.add_layout(LinearAxis(y_range_name='Performance ratio %'), 'right') ***
# loop through our columns and colors
for (columnnames, colore) in zip(col, mypalette):
p.line(df.index, df[columnnames], legend = columnnames, color = colore)
# creates an output file
output_file('<outputlocation>')
#save the plot
save(p)
Als Referenz sieht meine Datenrahmen wie folgt aus:
Datenrahmen wie folgt aussieht:
Time Col1 Col2 Col3 Col4
29/11/2016 00:00 4 41 41 55
29/11/2016 01:00 55 15 61 81
29/11/2016 02:00 51 75 2 4
29/11/2016 03:00 21 21 51 9
etc.
Bitte geben Sie eine Probe von 'df' (siehe [MCVE] (http://stackoverflow.com/help/mcve)) –
es auf die ursprüngliche Frage fügen Sie bitte –
Ein Beispiel eines Datenrahmens wurde jetzt zur ursprünglichen Frage hinzugefügt. – pottolom