Ubuntu18.04从系统自带的python2.7升至python3.6,并安装numpy、scipy、matplotlib

python2.7升至python3.6

查看系统中的python版本

python --version

在这里插入图片描述
看一下你是否之前安装装好了python3.6

which python
which python3.6
ls /usr/bin/python*

在这里插入图片描述
在这里插入图片描述
我之前已经装好了python3.6 ,你如果没有python3.x,需要安装一下,搜一下即可。
备份链接,

sudo cp /usr/bin/python /usr/bin/python_bak

先删除原来指向python2.7的链接,

sudo rm /usr/bin/python

建立链接指向python3.6。

sudo ln -s /usr/bin/python3.6 /usr/bin/python

完成
在这里插入图片描述

python3.6下安装numpy、scipy

安装scipy依赖包nose

sudo apt update
sudo apt upgrade
sudo apt install python3-nose

安装scipy(同时会自动安装numpy)

 sudo apt install python3-scipy

在这里插入图片描述
安装好了,简单测试一下

python
>>import numpy as np
>>np.test()

在这里插入图片描述
结果
在这里插入图片描述

python3.6安装matplotlib

sudo apt install python3-matplotlib

终端测试 ,不报错即成功

python
>>import matplotlib

官方样例代码测试

import numpy as np
import matplotlib.pyplot as plt

men_means, men_std = (20, 35, 30, 35, 27), (2, 3, 4, 1, 2)
women_means, women_std = (25, 32, 34, 20, 25), (3, 5, 2, 3, 3)

ind = np.arange(len(men_means))  # the x locations for the groups
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, men_means, width, yerr=men_std,
                color='SkyBlue', label='Men')
rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,
                color='IndianRed', label='Women')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend()


def autolabel(rects, xpos='center'):
    """
    Attach a text label above each bar in *rects*, displaying its height.

    *xpos* indicates which side to place the text w.r.t. the center of
    the bar. It can be one of the following {'center', 'right', 'left'}.
    """

    xpos = xpos.lower()  # normalize the case of the parameter
    ha = {'center': 'center', 'right': 'left', 'left': 'right'}
    offset = {'center': 0.5, 'right': 0.57, 'left': 0.43}  # x_txt = x + w*off

    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()*offset[xpos], 1.01*height,
                '{}'.format(height), ha=ha[xpos], va='bottom')


autolabel(rects1, "left")
autolabel(rects2, "right")

plt.show()

输出柱状图,到此全部完成。
在这里插入图片描述

参考博客:从系统自带python2.7升至python3.6
python3.6安装numpy、scipy
matplotlib代码测试

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值