Python MatplotLib不工作

2024-04-19 19:54:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这篇文章可能是重复的,但是我有一些matplotlib没有打印任何东西的问题,并且pythonshell输出中没有错误。甚至连一个小时都没有节目你知道吗

我尝试了pip卸载matplotlib,并从安装了最新的matplotlib-2.02.whllfd.uci.edu公司但我仍然有同样的问题,没有阴谋或错误的外壳。我假设这可能是由于matplotlib所依赖的另一个python扩展….(?)你知道吗

有人能给我发一些关于如何排除故障的信息吗?还有什么是matplotlib后端服务?我正在使用python 3.6

谢谢

from statistics import mean
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\test_SP data\\1st 

 GoRound\\testElectData.csv')

df = df[['kWhDay','CDDbase55']]
# print(df.head())

ys = df['kWhDay']
print(ys.head())
xs = df['CDDbase55']
print(xs.head())

def best_fit_slope_and_intercept(xs,ys):
    m = (((mean(xs) * mean(ys)) - mean(xs*ys)) /
         ((mean(xs)*mean(xs)) - mean(xs*xs)))
    b = mean(ys) - m*mean(xs)
    return m, b

m,b = best_fit_slope_and_intercept(xs,ys)

print(m)

regression_line = [(m*x)+b for x in xs]

plt.scatter(xs,ys)
plt.plot(xs, regression_line)
plt.show

Tags: csvimportdfmatplotlibas错误pltmean