我正在以两种不同的格式绘制相同的数据:对数比例和线性比例.
基本上我想要完全相同的情节,但有不同的尺度,一个在另一个的顶部.
我现在拥有的是:
import matplotlib.pyplot as plt
# These are the plot 'settings'
plt.xlabel('Size')
plt.ylabel('Time(s)');
plt.title('Matrix multiplication')
plt.xticks(xl, rotation=30, size='small')
plt.grid(True)
# Settings are ignored when using two subplots
plt.subplot(211)
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
plt.subplot(212)
plt.yscale('log')
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
Run Code Online (Sandbox Code Playgroud)
plt.subplot之前的所有'设置' 都将被忽略.
我可以按照我想要的方式工作,但是我必须在每个子图声明后复制所有设置.
有没有办法一次配置两个子图?
我正在尝试使用脚本为我生成一些makefile.我想格式化这个多行字符串,但我收到一个奇怪的错误.
码:
make_content = """ PCC = pgcc
%(bench)_serial: src/main.c src/%(bench)_serial.c ../common/util.c
\t$(PCC) $(ACCFLAGS) -o bin/%(bench)_serial src/main.c src/%(bench)_serial.c
clean:
\trm -rf *.o *.oo bin/*""" % {'bench':'umpalumpa'}
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "./new_bench.py", line 27, in <module>
\trm -rf *.o *.oo bin/*""" % {'bench':'umpalumpa'}
ValueError: unsupported format character '_' (0x5f) at index 21
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
注意:这是makefile的截断版本,没有评论.注释[2]:'umpalumpa'是占位符,以确保它是一个字符串.有一天它会成为真实的东西.
编辑:我正在使用python 2.7
我有一个像这样的元组列表(但更大):
t = [(1, 2, 3), (4, 5, 6)]
Run Code Online (Sandbox Code Playgroud)
我想要一个包含每个元组的所有第一个元素的列表.我有:
first = list(x[0] for x in t)
Run Code Online (Sandbox Code Playgroud)
假设我只想在数字小于EPS的情况下添加"第一个"数字.我想要的是:
first = list(x[0] for x in t, x[0] < EPS)
Run Code Online (Sandbox Code Playgroud)
但这不是一个有效的python语句.
我想知道这样做的pythonic方式是什么(我可以像在Java/C++中那样做,但我认为必须有更好的方法.