我有一台G700鼠标连接到我的电脑.这个鼠标在Linux(Ubuntu)中的问题是灵敏度非常高.我也不喜欢鼠标加速,所以我制作了一个脚本来关闭它.脚本看起来像这样
#!/bin/bash
# This script removes mouse acceleration, and lowers pointer speed
# Suitable for gaming mice, I use the Logitech G700.
# More info: http://www.x.org/wiki/Development/Documentation/PointerAcceleration/
xinput set-prop 11 'Device Accel Profile' -1
xinput set-prop 11 'Device Accel Constant Deceleration' 2.5
xinput set-prop 11 'Device Accel Velocity Scaling' 1.0
xinput set-prop 12 'Device Accel Profile' -1
xinput set-prop 12 'Device Accel Constant Deceleration' 2.5
xinput set-prop 12 'Device Accel Velocity Scaling' 1.0
Run Code Online (Sandbox Code Playgroud)
G700鼠标的另一个问题是它在xinput中显示为两个不同的设备.这很可能是因为鼠标有无线适配器,并且通常也通过USB电缆连接(用于充电).这是我的输出xinput --list(参见id 11和12):
$ xinput --list …Run Code Online (Sandbox Code Playgroud) 我正在使用Matplotlib创建绘图,我保存为SVG,使用Inkscape导出到.pdf + .pdf_tex,并在LaTeX文档中包含.pdf_tex文件.
这意味着我可以在标题,图例等中输入LaTeX命令,给出这样的图像

当我在我的LaTeX文档中使用它时,它会像这样呈现.请注意,轴上数字的字体会发生变化,并且图例中的LaTeX代码会被编译:

图的代码(如何导出到SVG这里没有显示,但可以根据要求显示):
import numpy as np
x = np.linspace(0,1,100)
y = x**2
import matplotlib.pyplot as plt
plt.plot(x, y, label = '{\\footnotesize \$y = x^2\$}')
plt.legend(loc = 'best')
plt.show()
Run Code Online (Sandbox Code Playgroud)
问题是,正如您所看到的那样,图例周围框的对齐和大小是错误的.这是因为当图像通过Inkscape + pdflatex时,标签文本的\footnotesize大小会发生变化(因为等等会消失,并且字体大小会发生变化).
我已经发现我可以选择标签的位置
plt.label(loc = 'upper right')
Run Code Online (Sandbox Code Playgroud)
或者如果我想要更多控制我可以使用
plt.label(bbox_to_anchor = [0.5, 0.2])
Run Code Online (Sandbox Code Playgroud)
但我没有找到任何方法使标签周围的盒子变小.这可能吗?
使盒子变小的另一种方法是使用类似的东西去除盒子的轮廓
legend = plt.legend()
legend.get_frame().set_edgecolor('1.0')
Run Code Online (Sandbox Code Playgroud)
然后将标签移动到我想要的位置.在这种情况下,我希望能够通过首先让python/matplotlib使用它来设置标签的位置
plt.label(loc = 'upper right')
Run Code Online (Sandbox Code Playgroud)
然后例如将它向右移动一点.这可能吗?我已经尝试使用get_bbox_to_anchor()和set_bbox_to_anchor(),但似乎无法得到它的工作.
我正在尝试为科学文章制作一些数字,所以我希望我的数字具有特定的大小.我还看到默认情况下Matplotlib在图形的边框上添加了大量填充,这是我不需要的(因为无论如何数字都将在白色背景上).
要设置一个特定的图形大小,我只需使用plt.figure(figsize = [w, h]),并添加参数tight_layout = {'pad': 0}以删除填充.这非常有效,如果我添加标题,y/x标签等,它甚至可以工作.示例:
fig = plt.figure(
figsize = [3,2],
tight_layout = {'pad': 0}
)
ax = fig.add_subplot(111)
plt.title('title')
ax.set_ylabel('y label')
ax.set_xlabel('x label')
plt.savefig('figure01.pdf')
Run Code Online (Sandbox Code Playgroud)
这将创建一个精确大小为3x2(英寸)的pdf文件.
我遇到的问题是,当我在轴外添加一个文本框(通常是一个图例框)时,Matplotlib不会像添加标题/轴标签时那样为文本框腾出空间.通常,文本框被截断,或者根本不显示在已保存的图中.例:
plt.close('all')
fig = plt.figure(
figsize = [3,2],
tight_layout = {'pad': 0}
)
ax = fig.add_subplot(111)
plt.title('title')
ax.set_ylabel('y label')
ax.set_xlabel('x label')
t = ax.text(0.7, 1.1, 'my text here', bbox = dict(boxstyle = 'round'))
plt.savefig('figure02.pdf')
Run Code Online (Sandbox Code Playgroud)
我在其他地方找到的解决方案是将参数添加bbox_inches = 'tight'到savefig命令.文本框现在包含在我想要的内容中,但pdf现在的大小错误.似乎Matplotlib只是使图形更大,而不是像添加标题和x/y标签时那样减小轴的大小.
例:
plt.close('all')
fig = plt.figure(
figsize = [3,2], …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来右键单击Windows 10中的文件,选择"打开方式" - >"Sublime Text",然后出现一个新的 Sublime Text窗口.
如果Sublime已经打开,则默认操作是在新选项卡中打开文件.这通常不是我想要的,特别是因为我通常在不同的桌面上打开Sublime.
我已经尝试使用-n添加的标志创建一个快捷方式,这只是在使用快捷方式时正确地给了我一个新窗口.但是当我使用该快捷方式"打开"时,它会在现有窗口中打开文件.
我也尝试过"打开"一个包含subl -n"但是唉"的批处理文件.
有没有办法检测python脚本是从python或ipython shell运行,还是从命令行运行,例如python scrip.py?
我想使用它来设置我的matplotlib环境,并根据脚本的运行方式保存或显示数字.当我从命令行运行绘图脚本时,我希望脚本使用非标准的matplotlib后端并将图形保存到文件中plt.savefig(),但如果我从ipython shell中运行它In [1]: run scrip.py,我希望使用显示图形plt.show().
像这样的东西:
import matplotlib
if run_from_command_line:
matplotlib.use("non-standard-backend")
import matplotlib.pyplot as plt
if run_from_interactive_shell:
plt.ion() // Turn on interactive mode in matplotlib
// Do plotting
if run_from_command_line:
plt.savefig(filename)
else:
plt.show()
Run Code Online (Sandbox Code Playgroud) 给出以下代码
#include <vector>
#include <memory>
using namespace std;
class MyBase
{};
class MyDerived : public MyBase
{};
template<class Base, class Derived>
vector<Base> makeBaseVec(const Derived& obj, const typename vector<Base>::size_type size)
{
vector<Base> out;
for (typename vector<Base>::size_type i = 0; i < size; i++)
{
out.push_back(Base(obj) /* copy constructor */);
}
return out;
}
int main()
{
MyDerived a;
vector<MyBase> v = makeBaseVec<MyBase>(a, 10);
}
Run Code Online (Sandbox Code Playgroud)
为什么我会收到错误
main.cpp:13:14: note: template argument deduction/substitution failed:
main.cpp:29:41: note: couldn't deduce template parameter 'Base'
vector<MyBase> v …Run Code Online (Sandbox Code Playgroud) matplotlib ×3
python ×2
c++ ×1
ipython ×1
legend ×1
shell ×1
sublimetext ×1
templates ×1
windows-10 ×1
xinput ×1