python - x 值重叠的散景图
问题描述
我用散景库做了一个绘图,除了 x 分类变量的重叠之外,输出似乎没问题。
有一种简单的方法可以将每个月分开,因此彼此之间没有重叠?
我尝试使用 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"}]}
这是我的代码和输出:
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))
解决方案
避免标签重叠的两种明显方法:
通过设置 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)
旋转 X 轴标签(不要忘记导入 pi):
p.xaxis.major_label_orientation = pi/4
推荐阅读
- r - R中一张图中的多个时间序列图
- c - Windows 上的 VC2019 地址清理程序 64 位链接错误“未解析的外部符号 __asan_shadow_memory_dynamic_address”
- r - R绘图功能:增加图例刻度刻度标签的大小
- web - 在进行网络钓鱼意识活动时如何使我的网站不危险?
- c# - 如何在 PageModel 中为表单分配属性(按按钮),维护选定的页面布局 [ASP.NET/Razor 页面]
- ios - 如何使用 Firebase 防止当前用户的个人资料显示在 collectionView 中
- ssl - 使用 Kubernetes 和 Helm 设置多个 TLS 证书和域
- android - “search?.actionView as SearchView”在移动到第二个 Activity 时崩溃
- python - 将“打字”对象作为参数传递?
- r - R 单样本 KS 测试