小编fgb*_*fgb的帖子

使用savefig()将图形导出为pdf会使matplotlib中的轴背景混乱

我正在尝试更改绘图中的轴背景,其中多个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)

python macos matplotlib osx-mountain-lion

5
推荐指数
1
解决办法
8610
查看次数

scipy.ndimage.interpolation.rotate中的'axes'参数

我不太明白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个整数的元组,可选

两个轴定义旋转平面.默认是前两个轴.

两个轴可以定义一个旋转平面吗?

python numpy scipy

4
推荐指数
1
解决办法
1783
查看次数

Python 3:如何将项目从列表x移动到列表y并从列表x中删除它?

我想.append从列表中随机卡DeckMyHand,而从取出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),但它说选择不在甲板上.

python random list append python-3.x

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

搜索特定字符串,复制到文本文件中,如果不存在,则产生错误

这与我之前提出的问题类似.但我决定让它变得更复杂一些.

我正在创建一个程序,可以读取文本文件并将文本文件的特定部分复制到另一个文本文件中.但是,我也希望生成错误消息.

例如,我的文本文件如下所示:

* 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 string copy text-files

0
推荐指数
1
解决办法
1277
查看次数