小编lan*_*uze的帖子

autofmt_xdate删除所有子图的x轴标签

我用它autofmt_xdate以可读的方式绘制长x轴标签.问题是,当我想要组合不同的子图时,其他子图的x轴标记消失了,我不喜欢下图中最左边的子图(两行高).有没有办法防止autofmt_xdate淬火其他x轴标签?或者还有另一种旋转标签的方法吗?正如你所看到的那样,我也进行了实验xticks和"旋转",但结果并不令人满意,因为标签围绕它们的中心旋转,导致标签混乱.

产生以下情节的脚本:

from matplotlib import pyplot as plt
from numpy import arange
import numpy
from matplotlib import rc

rc("figure",figsize=(15,10))
#rc('figure.subplot',bottom=0.1,hspace=0.1)
rc("legend",fontsize=16)
fig = plt.figure()


Test_Data = numpy.random.normal(size=20)

fig = plt.figure()
Dimension = (2,3)
plt.subplot2grid(Dimension, (0,0),rowspan=2)
plt.plot(Test_Data)
plt.subplot2grid(Dimension, (0,1),colspan=2)
for i,j in zip(Test_Data,arange(len(Test_Data))):
    plt.bar(i,j)
plt.legend(arange(len(Test_Data)))
plt.subplot2grid(Dimension, (1,1),colspan=2)
xticks = [r"%s (%i)" % (a,b) for a,b in zip(Test_Data,Test_Data)]
plt.xticks(arange(len(Test_Data)),xticks)
fig.autofmt_xdate()
plt.ylabel(r'$Some Latex Formula/Divided by some Latex Formula$',fontsize=14)
plt.plot(Test_Data)
#plt.setp(plt.xticks()[1],rotation=30)
plt.tight_layout()
#plt.show()
Run Code Online (Sandbox Code Playgroud)

由脚本创建的图

python matplotlib

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

python float to int转换

我有一个让我疯狂的问题.通常做int(20.0)会导致20.到现在为止还挺好.但:

levels = [int(gex_dict[i]) for i in sorted(gex_dict.keys())]
Run Code Online (Sandbox Code Playgroud)

while gex_dict[i]返回一个float,例如20.0,结果为:

"invalid literal for int() with base 10: '20.0'"
Run Code Online (Sandbox Code Playgroud)

我离咀嚼最后一块键盘只有一步之遥.

python floating-point

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

Julia,在迭代字典时更改键时的奇怪行为

我经历了(在我看来)奇怪的行为,同时迭代Julia字典并在迭代期间查找键名.以下示例按预期工作:

a = Dict("klaus_one" => 3,
         "bernd_one" => 5,
         "gabi_one" => 8)

for i= keys(a)
     x = pop!(a,i)
     a[join([i,"new"],"_")] = x + 3
end
Run Code Online (Sandbox Code Playgroud)

退货(按预期)

# Dict{ASCIIString,Int64} with 3 entries:
#   "gabi_one_new"  => 11
#   "bernd_one_new" => 8
#   "klaus_one_new" => 6
Run Code Online (Sandbox Code Playgroud)

然而:

a = Dict("klaus_one" => 3,
         "bernd_one" => 5,
         "gabi_one" => 8)

for i=1:5

    if i!=1

        # _keys = deepcopy(keys(a))
        _keys = keys(a)
        for k = _keys
            k_base = join(split(k,"_")[1:2],"_")
            a[k_base] = pop!(a,k) + 3 
        end
    end
    # …
Run Code Online (Sandbox Code Playgroud)

dictionary iterator julia

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