将spearmanr结果四舍五入到小数点后3位

时间:2017-05-12 01:35:50

标签: python-3.x matplotlib scipy

如果我想把它作为注释添加到我的情节中,如何将spearmanr结果舍入到3位小数?

pip install --install-option="--prefix=/home/myuser" awscli

DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
/home/myuser/.local/lib/python2.6/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Collecting awscli
  Using cached awscli-1.11.85.tar.gz
Collecting botocore==1.5.48 (from awscli)
  Using cached botocore-1.5.48.tar.gz
Collecting colorama<=0.3.7,>=0.2.5 (from awscli)
  Using cached colorama-0.3.7.zip
Requirement already satisfied: docutils>=0.10 in ./lib/python2.6/site-packages (from awscli)
Requirement already satisfied: rsa<=3.5.0,>=3.1.2 in /usr/lib/python2.6/dist-packages (from awscli)
Collecting s3transfer<0.2.0,>=0.1.9 (from awscli)
  Using cached s3transfer-0.1.10.tar.gz
Requirement already satisfied: PyYAML<=3.12,>=3.10 in /usr/lib64/python2.6/dist-packages (from awscli)
Requirement already satisfied: argparse>=1.1 in ./.local/lib/python2.6/site-packages (from awscli)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in ./lib/python2.6/site-packages (from botocore==1.5.48->awscli)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./lib/python2.6/site-packages/python_dateutil-2.6.0-py2.6.egg (from botocore==1.5.48->awscli)
Collecting ordereddict==1.1 (from botocore==1.5.48->awscli)
  Using cached ordereddict-1.1.tar.gz
Collecting simplejson==3.3.0 (from botocore==1.5.48->awscli)
  Using cached simplejson-3.3.0.tar.gz
Requirement already satisfied: pyasn1>=0.1.3 in /usr/lib/python2.6/dist-packages (from rsa<=3.5.0,>=3.1.2->awscli)
Collecting futures<4.0.0,>=2.2.0 (from s3transfer<0.2.0,>=0.1.9->awscli)
  Using cached futures-3.1.1.tar.gz
Requirement already satisfied: six>=1.5 in /usr/lib/python2.6/dist-packages (from python-dateutil<3.0.0,>=2.1->botocore==1.5.48->awscli)
Skipping bdist_wheel for awscli, due to binaries being disabled for it.
Skipping bdist_wheel for botocore, due to binaries being disabled for it.
Skipping bdist_wheel for colorama, due to binaries being disabled for it.
Skipping bdist_wheel for s3transfer, due to binaries being disabled for it.
Skipping bdist_wheel for ordereddict, due to binaries being disabled for it.
Skipping bdist_wheel for simplejson, due to binaries being disabled for it.
Skipping bdist_wheel for futures, due to binaries being disabled for it.
Installing collected packages: ordereddict, simplejson, botocore, colorama, futures, s3transfer, awscli
  Found existing installation: ordereddict 1.2
    DEPRECATION: Uninstalling a distutils installed project (ordereddict) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling ordereddict-1.2:
Exception:
Traceback (most recent call last):
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/req/req_uninstall.py", line 120, in remove
    self.dist.project_name, self.dist.version
  File "/usr/lib64/python2.6/contextlib.py", line 34, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/utils/logging.py", line 36, in indent_log
    yield
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/home/myuser/.local/lib/python2.6/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib64/python2.6/shutil.py", line 261, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/lib64/python2.6/dist-packages/ordereddict-1.2-py2.6.egg-info'

Output 我希望注释保留在图表中。

1 个答案:

答案 0 :(得分:1)

重新格式化注释中的文本。用这个替换倒数第二行:

r = scipy.stats.spearmanr(year, percent)
text = "correlation: {:.3f}, pvalue:{:.3f}".format(r.correlation, r.pvalue)
ax.annotate(text, xy=(2009,70))

输出

enter image description here