Pycharm does not show plot

后端 未结 25 1123
鱼传尺愫
鱼传尺愫 2020-12-04 09:13

Pycharm does not show plot from the following code:

import pandas as pd
import numpy as np
import matplotlib as plt

ts = pd.Series(np.random.randn(1000), in         


        
25条回答
  •  悲&欢浪女
    2020-12-04 09:35

    I was facing above error when i am trying to plot histogram and below points worked for me.

    OS : Mac Catalina 10.15.5

    Pycharm Version : Community version 2019.2.3

    Python version : 3.7

    1. I changed import statement as below (from - to)

    from :

    import matplotlib.pylab as plt

    to:

    import matplotlib.pyplot as plt

    1. and plot statement to below (changed my command form pyplot to plt)

    from:

    plt.pyplot.hist(df["horsepower"])
    
    # set x/y labels and plot title
    plt.pyplot.xlabel("horsepower")
    plt.pyplot.ylabel("count")
    plt.pyplot.title("horsepower bins") 
    
    

    to :

    plt.hist(df["horsepower"])
    
    # set x/y labels and plot title
    plt.xlabel("horsepower")
    plt.ylabel("count")
    plt.title("horsepower bins")
    
    1. use plt.show to display histogram

    plt.show()

提交回复
热议问题