zoukankan      html  css  js  c++  java
  • 使用matplot做图--sin图像

    # _*_ coding:utf-8 _*_
    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(-5, 5, 0.1)
    y = np.sin(x)
    plt.plot(x, y)
    plt.show()

    这里插入一个可能会碰到的问题:

    I am trying to import matplotlib like so:
    
    import matplotlib.pyplot as plt
    For this I have installed matplotlib using.
    
    python -m pip install -U pip setuptools
    python -m pip install matplotlib
    Although the basic_example.py from the examples worked, it suddenly stopped running along with all other files with matplotlib giving me the below error:
    
    File "matplotlib.py", line 2, in <module>
      import matplotlib.pyplot as plt # pyplot module.
    ImportError: No module named pyplot`
    I tried to check if the module is still there, and it seems to be. What could be possibly wrong?
    
    Requirement already satisfied: matplotlib in c:python27libsite-packages
    Requirement already satisfied: numpy>=1.6 in c:python27libsite-packages (from matplotlib)
    Requirement already satisfied: python-dateutil in c:python27libsite-packages (from matplotlib)
    Requirement already satisfied: cycler in c:python27libsite-packages (from matplotlib)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,>=1.5.6 in c:python27libsite-packages (from matplotlib)
    Requirement already satisfied: pytz in c:python27libsite-packages (from matplotlib)
    Requirement already satisfied: six>=1.5 in c:python27libsite-packages (from python-dateuti

    简单的说就是,安装了模块,但是出现模块导入错误。

    看看回答:

    Python 2.7 tries to find modules in the current working directory first, before
    going into the installed packages, so because you named your test file "matplotlib.py",
    it will interpret it as the matplotlib package. Rename your test file to something else, and it should be fine

    是的,检查一下你的文件名是不是跟导入的模块名重复了。。。。

  • 相关阅读:
    Python小白的数学建模 ---- 系列课程
    Maven学习笔记
    JavaScript 中的 Var,Let 和 Const 有什么区别
    (鸡汤文)搞懂了 JavaScript 定时器 setTimeout() 的 this 指向!
    setTimeout返回值的验证,(〒︿〒) 请原谅我一直以来对你的忽视
    终于把初中到大学的数学知识梳理完了(学习算法必备数学知识)
    最简单入门深度学习
    机器学习基本流程
    Vue.js源码解析-Vue初始化流程
    最大公约数&最小公倍数
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/6687137.html
Copyright © 2011-2022 走看看