[英]Bokeh plot with x values overlap
I did a plot with the bokeh library, the output seems OK except for a overlapping of the x categorical variables.我用散景库做了一个绘图,除了 x 分类变量的重叠外,输出似乎还可以。
There is a simple way to separate each month so there is no overlap between each other ?有一种简单的方法可以将每个月分开,这样彼此之间就没有重叠?
I tried with dodge() but I couldn't define the parameters inside the function我尝试使用 dodge() 但我无法在函数内部定义参数
cumple.txt file:
{"people":
[{"name": "daniela", "birthday": "8/05/1990"},
{"name": "mariano", "birthday": "5/08/1990"},
{"name": "agustin", "birthday": "27/11/1993"},
{"name": "laura", "birthday": "20/10/2000"}]}
Here is my code and the output:这是我的代码和输出:
from collections import Counter
import json
from bokeh.plotting import figure, show, output_file
with open("cumple.txt", "r") as f:
info = json.load(f)#carga todo el dictionario en info
s=[]
for i in info['people']:
s.append(i['birthday'])
months=[]
num_to_string = {
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",
11: "November",
12: "December"
}
month=0
for x in s:
month=int(x.split('/')[1])[![enter image description here][1]][1]
months.append(num_to_string[month])
output_file("figura.html")
x_categories = []
for u in num_to_string.values():
x_categories.append(u)
print(x_categories)
x=[]
for j in months:
x.append(j)
print (x)
y=[]
for r in Counter(months).values():
y.append(r)
print(y)
p = figure(title='cumple de amigos',x_range=x_categories, x_axis_label='months', y_axis_label='amount of birthdays')
p.title.align = 'center'
p.vbar(x=x, top=y, width=0.5)
show(p)
print(Counter(months))
Two obvious ways to avoid the labels overlapping:避免标签重叠的两种明显方法:
Increase the width of the graph by setting plot_width:通过设置 plot_width 增加图形的宽度:
p = figure(title='cumple de amigos',x_range=x_categories, x_axis_label='months', y_axis_label='amount of birthdays', plot_width=1000)
Rotate the X-axis labels (don't forget to import pi):旋转 X 轴标签(不要忘记导入 pi):
p.xaxis.major_label_orientation = pi/4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.