散景:糟糕的日期格式?

问题描述 投票:-4回答:1

有人会建议我如何调整X轴以更好地显示此图表上的日期吗?


from math import pi
import pandas as pd
from bokeh.io import show
from bokeh.models import LinearColorMapper, BasicTicker, PrintfTickFormatter, ColorBar
from bokeh.plotting import figure

#cesta k souboru
path = "C://Users//Zemi4//Desktop//zpr3//all2.csv"

#nacteni dataframu
data = pd.read_csv(path, delimiter = ",")

data['Cas'] = data['Cas'].astype(str)
data = data.set_index('Cas')
data.columns.name = 'Mistnost'

times = list(data.index)
rooms = list(data.columns)

df = pd.DataFrame(data.stack(), columns=['float']).reset_index()

colors = ['#440154', '#404387', '#29788E', '#22A784', '#79D151', '#FDE724', '#FCFEA4', '#FBA40A', '#DC5039']
mapper = LinearColorMapper(palette=colors, low=df.float.min(), high=df.float.max())

TOOLS = "hover,save,pan,box_zoom,reset,wheel_zoom"

p = figure(title="Heatmap ({0} - {1})".format(times[0], times[-1]),
           x_range=times, y_range=list(reversed(rooms)),
           x_axis_location="above", plot_width=1500, plot_height=900,
           tools=TOOLS, toolbar_location='below',
           tooltips=[('Time: ', '@Cas'), ('Temperature: ', '@float'), ('Room: ', '@Mistnost')],
           x_axis_type='datetime')

p.grid.grid_line_color = None
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_text_font_size = "5pt"
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = pi / 3

p.rect(x="Cas", y="Mistnost", width=1, height=1,
       source=df,
       fill_color={'field': 'float', 'transform': mapper},
       line_color=None)

color_bar = ColorBar(color_mapper=mapper, major_label_text_font_size="5pt",
                     ticker=BasicTicker(desired_num_ticks=len(colors)),
                     formatter=PrintfTickFormatter(format="%f"),
                     label_standoff=6, border_line_color=None, location=(0, 0))
p.add_layout(color_bar, 'right')

show(p)      # show the pl
pandas plotly bokeh
1个回答
0
投票

尝试:p.xaxis[0].ticker.desired_num_ticks = <number_ticks_you_want_to_display>。或者像使用ColorBar一样应用特定的自动收报机(请参阅Bokeh docs)。

© www.soinside.com 2019 - 2024. All rights reserved.