我正在尝试更改绘图中的轴背景,其中多个imshow()
调用通过extent
参数在不同位置渲染图像.
当我使用保存图的pdf时savefig()
,如果轴显示多个图像,则会丢失背景颜色.请注意,导出相同数字的png时不会发生这种情况.
这是一个说明问题的最小脚本:
import matplotlib.pyplot as plt
from numpy.random import rand
fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True)
ax[0].imshow(rand(15,15), extent=[0, 2, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[0].set_axis_bgcolor('k')
ax[1].imshow(rand(15,15), extent=[0, 2, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[1].imshow(rand(15,15), extent=[4, 6, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[1].set_axis_bgcolor('k')
ax[2].imshow(rand(15,15), extent=[0, 2, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[2].imshow(rand(15,15), extent=[4, 6, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[2].imshow(rand(15,15), extent=[8, 10, 15, 0], \
cmap=plt.cm.gray, aspect='auto', interpolation='Nearest')
ax[2].set_axis_bgcolor('k') …
Run Code Online (Sandbox Code Playgroud) 我不太明白axes
以下旋转功能中的参数:
scipy.ndimage.interpolation.rotate(input, angle, axes=(1, 0), reshape=True, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
Run Code Online (Sandbox Code Playgroud)
文档中给出的解释如下:
axes:2个整数的元组,可选
两个轴定义旋转平面.默认是前两个轴.
两个轴可以定义一个旋转平面吗?
我想.append
从列表中随机卡Deck
来MyHand
,而从取出Deck
.
import random
Deck = []
MyHand = []
CardsPicked = 0
for Cards in range(1, 101):
Deck.append(Cards)
while(CardsPicked < 8):
MyHand.append(random.choice(Deck))
CardsPicked = CardsPicked + 1
Run Code Online (Sandbox Code Playgroud)
要知道的事情:我已经能够添加卡,但不能删除它.
我试过了Deck.remove(random.choice)
,但它说选择不在甲板上.
这与我之前提出的问题类似.但我决定让它变得更复杂一些.
我正在创建一个程序,可以读取文本文件并将文本文件的特定部分复制到另一个文本文件中.但是,我也希望生成错误消息.
例如,我的文本文件如下所示:
* VERSION_1_1234
#* VERSION_2_1234
* VERSION_3_1234
#* VERSION_2_4321
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的程序通过"VERSION_2"行查看并将该行复制到另一个文本文件中.
但现在,我希望它搜索"VERSION_3",如果它找到"VERSION_2"和"VERSION_3",它将产生错误.
这是我到目前为止所拥有的:
with open('versions.txt', 'r') as verFile:
for line in verFile:
# if pound sign, skip line
if line.startswith('#'):
continue
# if version_3 there, copy
if 'VERSION_3_' in line:
with open('newfile.txt', 'w') as wFile:
wFile.write(line.rpartition('* ')[-1])
# if version_2 there, copy
if 'VERSION_2_' in line:
with open('newfile.txt', 'w') as wFile:
wFile.write(line.rpartition('* ')[-1])
# if both versions there, produce error
if ('VERSION_3_' and 'VERSION_2_') in line:
print ('There's an …
Run Code Online (Sandbox Code Playgroud) python ×4
append ×1
copy ×1
list ×1
macos ×1
matplotlib ×1
numpy ×1
python-3.x ×1
random ×1
scipy ×1
string ×1
text-files ×1