python - 设置matplotlib样式时出现AttributeError

标签 python matplotlib

我有一个使用以下导入列表的 python 脚本:

import matplotlib
matplotlib.style.use('ggplot')

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

然后它将文本文件导入到数据框中,在 df 中创建一些额外的列并创建两个图。

我需要能够从 Matlab 调用它(出于一些乏味的原因......),我通过在 Matlab 提示符下键入以下内容来完成此操作:

dos('myfile.py')

抛出以下错误:

Traceback (most recent call last): 
  File "D:\Documents\Python Scripts\XXXXXXXXX.py", line 8, in     <module> 
    matplotlib.style.use('ggplot') 
AttributeError: 'module' object has no attribute 'style' 

但是,如果我评论要求 ggplot 样式的行,它运行良好并以标准 matplotlib 格式正确生成绘图。

关于为什么会出现这种情况有什么建议吗?

最好的问候,

最佳答案

style是pyplot的属性,不是matplotlib

尝试:

import matplotlib.pyplot as plt
plt.style.use('ggplot')

关于python - 设置matplotlib样式时出现AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29919233/

相关文章:

python - 将 "django-admin.py"路径添加到 Windows 7 上的命令行

python-3.x - 如何使用 matplotlib/python 绘制 ROC 曲线

python - 使用 pyplot 在不等轴上绘制圆

python - 在 Bokeh 中调整 matplotlib 标记大小?

python - 绘制二维数组的曲面图

python - 使用 matplotlib 动画库对二分法进行动画处理

python - Django-filter 'icontains' 没有传递到我的 URL

Python 3 : I am trying to find find all green pixels in an image by traversing all pixels using an np. 数组,但无法解决索引错误

python - Pygame health/maxhealth = 0.0 而不是 0.66

python - matplotlib scatter 在 ipython 笔记本中有效,但在控制台中无效