我的水平颜色条上的标签太靠近了,我不想进一步减小文字大小:
cbar = plt.colorbar(shrink=0.8, orientation='horizontal', extend='both', pad=0.02)
cbar.ax.tick_params(labelsize=8)

我想保留所有刻度,但删除所有其他标签.
我发现的大多数示例都将用户指定的字符串列表传递给cbar.set_ticklabels().我正在寻找一个通用的解决方案.
我玩弄各种变化
cbar.set_ticklabels(cbar.get_ticklabels()[::2])
和
cbar.ax.xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(nbins=4))
但我还没有找到神奇的组合.
我知道必须有一个干净的方法来使用定位器对象.
> pip install yolk
Downloading/unpacking yolk
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement yolk
No distributions at all found for yolk
Storing complete log in /Users/harith/.pip/pip.log
当我看到我看到的文件时
> cat /Users/harith/.pip/pip.log
------------------------------------------------------------
/Users/harith/.shared/virtualenvs/pennytracker/bin/pip run on Mon Jul  1 20:26:02 2013
Downloading/unpacking yolk
  Getting page https://pypi.python.org/simple/yolk/
  Could not fetch URL https://pypi.python.org/simple/yolk/: HTTP Error 503: Service Unavailable
  Will skip URL https://pypi.python.org/simple/yolk/ when looking for download links for yolk
  Getting page https://pypi.python.org/simple/
  Could not fetch URL …我想创建一个shell脚本,可以永久地更改我的Ubuntu的主机名.每当我使用该hostname New_hostname命令时,它会在我重新启动机器后返回到原始主机名.
我发现我可以永久改变它的唯一方法是修改文件/etc/hostname并保存.有没有办法只使用shell脚本才能做到这一点?我也有密码.
我想在Python中编写一个函数,它将一个切片作为参数.理想情况下,用户可以按如下方式调用该函数:
foo(a:b:c)
不幸的是,这种语法不Python允许-使用a:b:c只允许范围内[],没有().
因此,我认为我的功能有三种可能性:
要求用户使用切片"构造函数"(其s_行为类似于numpy提供的版本):
foo(slice(a, b, c))
foo(s_[a:b:c])
将我的函数的逻辑放入一个__getitem__方法:
foo[a:b:c]
放弃尝试切片并单独开始,停止和步骤:
foo(a, b, c)
有没有办法让原始语法工作?如果不是,首选哪种解决方法语法?或者还有另一种更好的选择吗?
我需要将两个动作之间的时差(差异)转换为人类可读时间.
我怎么能用python做到这一点?我试过类似的东西
    diff = 49503757
    datetime.time(0,0,0,diff)
但是diff值太长,datetime期望在0到999999之间的微秒值,在这个例子中我的差异是49503757.
我有一个.tgz大小为2GB 的文件.
我想.txt从.tgz文件中只提取一个大小为2KB的文件.
我有以下代码:
import tarfile
from contextlib import closing
with closing(tarfile.open("myfile.tgz")) as tar:
    subdir_and_files = [
        tarinfo for tarinfo in tar.getmembers()
        if tarinfo.name.startswith("myfile/first/second/text.txt")
        ]
    print subdir_and_files
    tar.extractall(members=subdir_and_files)
问题是我得到提取的文件至少需要一分钟.似乎extractall提取所有文件,但只保存我问的那个.
有没有更有效的方法来实现它?
现在我正在努力在你的屏幕上制作Python"类型"(我感到无聊和实验),而且我自己得到了这么多,但我找不到任何方法在我的脚本中使用小数,如Python只接受randint()的整数.
#include <stdio.h>;
import sys;
import time;
import os;
import random;
os.system("clear");
script = "I just really need to type something right now. I'm not sure why, but I really feel like typing on the Chromebook right now. It seems kinda weird, but I like doing this. It helps me practice what I'm doing. I've noticed that I'm a lot worse at typing lately, and I don't know why. Maybe it's because I've been working with a chunky keyboard, and …