小编leg*_*gel的帖子

如何在一个点上水平居中注释?

我想把这个代码用于散点图注释...

import matplotlib; matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

labels = ["Abra", "Kadabra", "Alazkazam", "Mew"]
x_values = [0.3, 0.6, 0.2, 0.4]
y_values = [0.2, 0.2, 0.4, 0.9]

fig = plt.figure(figsize=(5, 5))
plt.axis('off')

renderer = fig.canvas.get_renderer()

for i, label in enumerate(labels):
    plt.scatter(x_values[i], y_values[i])
    text_object = plt.annotate(label, xy=(x_values[i], y_values[i]))

plt.savefig("horizontally_centered_text_annotations.png")
Run Code Online (Sandbox Code Playgroud)

......产生这个情节: 没有居中的注释

...并使它产生类似这样的情节: 带中心的注释

我试过在文本框周围获取窗口范围,抓取x坐标和宽度,并为每个注释移位,如下所示:

for i, label in enumerate(labels):
    plt.scatter(x_values[i], y_values[i])
    text_object = plt.annotate(label, xy=(x_values[i], y_values[i]))
    text_window_extent = text_object.get_window_extent(renderer)
    new_x_position = x_values[i] - text_window_extent.width / 2
    text_object.set_position((new_x_position, y_values[i]))
    print "x_value: {}, window_extent_width: {}, new_x_position: …
Run Code Online (Sandbox Code Playgroud)

graphics matplotlib

18
推荐指数
1
解决办法
5747
查看次数

如何使用 Google Chromium GN 构建目标?

我正在尝试使用GN从源代码构建ChromeDriver的可执行目标,我使用Depot Tools 将其安装在我的 PATH 目录中,但是当我运行时出现此错误:gn BUILD.gn

gn.py: Could not find checkout in any parent of the current path.
This must be run inside a checkout.
Run Code Online (Sandbox Code Playgroud)

如果我没有正确设置,我不确定是否需要检查整个 Chromium 目录?

更新

我已经在gn_tool的帮助下下载了 gn 的工作二进制文件。

我仍然不确定我应该为“构建 chromedriver 目标”运行什么命令,因为现在我尝试的每个命令似乎都给我这个错误:

ERROR Can't find source root. I could not find a ".gn" file in the current directory or any parent,and the --root command-line argument was not specified.
Run Code Online (Sandbox Code Playgroud)

...即使在我运行 gn 的目录中有一个 BUILD.gn 文件...

chromium selenium-chromedriver gn

8
推荐指数
1
解决办法
8743
查看次数

解决EC2上Ubuntu 16.04的overcommit_memory和透明大页面上的Redis警告

在新的Ubuntu 16.04 EC2实例上,警告如下所示:

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to …
Run Code Online (Sandbox Code Playgroud)

ubuntu amazon-ec2 redis sysctl huge-pages

7
推荐指数
1
解决办法
7537
查看次数