Pycharm does not show plot

后端 未结 25 1055
鱼传尺愫
鱼传尺愫 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

    For beginners, you might also want to make sure you are running your script in the console, and not as regular Python code. It is fairly easy to highlight a piece of code and run it.

    0 讨论(0)
  • 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()

    0 讨论(0)
  • 2020-12-04 09:38

    Soon after calling

    plt.imshow() 
    

    call

    plt.show(block = True)
    

    You will get the matplotlib popup with the image.

    This is a blocking way. Further script will not run until the pop is closed.

    0 讨论(0)
  • 2020-12-04 09:39

    With me the problem was the fact that matplotlib was using the wrong backend. I am using Debian Jessie.

    In a console I did the following:

    import matplotlib
    matplotlib.get_backend()
    

    The result was: 'agg', while this should be 'TkAgg'.

    The solution was simple:

    1. Uninstall matplotlib via pip
    2. Install the appropriate libraries: sudo apt-get install tcl-dev tk-dev python-tk python3-tk
    3. Install matplotlib via pip again.
    0 讨论(0)
  • 2020-12-04 09:40

    I have found a solution. This worked for me:

    import numpy as np
    import matplotlib.pyplot as plt
    
    points = np.arange(-5, 5, 0.01)
    dx, dy = np.meshgrid(points, points)
    z = (np.sin(dx)+np.sin(dy))
    plt.imshow(z)
    plt.colorbar()
    plt.title('plot for sin(x)+sin(y)')
    plt.show()
    
    0 讨论(0)
  • 2020-12-04 09:40

    i had this problem and i could solve it , you can test my way.. disable "show plots in tool window" from setting-->tools-->python scientific

    0 讨论(0)
提交回复
热议问题