在本文中,我们将带你了解将matplotlib对象加载到reportlab中在这篇文章中,我们将为您详细介绍将matplotlib对象加载到reportlab中的方方面面,并解答matplotlib导
在本文中,我们将带你了解将matplotlib对象加载到reportlab中在这篇文章中,我们将为您详细介绍将matplotlib对象加载到reportlab中的方方面面,并解答matplotlib导入数据作图常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的4.1Python数据处理篇之Matplotlib系列(一)---初识Matplotlib、Help on module matplotlib.cm in matplotlib:、import matplotlib.pyplot as plt出错、importError: DLL load failed when import matplotlib.pyplot as plt。
本文目录一览:- 将matplotlib对象加载到reportlab中(matplotlib导入数据作图)
- 4.1Python数据处理篇之Matplotlib系列(一)---初识Matplotlib
- Help on module matplotlib.cm in matplotlib:
- import matplotlib.pyplot as plt出错
- importError: DLL load failed when import matplotlib.pyplot as plt
将matplotlib对象加载到reportlab中(matplotlib导入数据作图)
我正在尝试将matplotlib对象加载到reportlab。这是我的代码:
from reportlab.pdfgen import canvasfrom reportlab.lib.utils import ImageReaderfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Imagefrom matplotlib import pyplot as pltdef __get_img_data(): """ returns the binary image data of the plot """ img_file = NamedTemporaryFile(delete=False) plt.savefig(img_file.name) img_data = open(img_file.name + ''.png'', ''rb'').read() os.remove(img_file.name) os.remove(img_file.name + ''.png'') return img_datadef get_plot(): # HERE I PLOT SOME STUFF img_data = __get_img_data() plt.close() return img_dataclass NumberedCanvas(canvas.Canvas): def __init__(self): passclass ReportTemplate: def __init__(self): pass def _header_footer(self, canvas, doc): pass def get_data(self): elements = [] elements.append(''hello'') ## HERE I WANT TO ADD THE IMAGE imgdata = get_plot() with open(''/tmp/x.png'', ''wb'') as fh: fh.write(imgdata) im = Image(''/tmp/x.png'', width=usable_width, height=usable_width) elements.append(im) os.remove(''/tmp/x.png'') ###### doc.build(elements, onFirstPage=self._header_footer,\ onLaterPages=self._header_footer,\ canvasmaker=NumberedCanvas) # blah blah return obj
我的目标是将绘图图像插入报告中。这工作正常,但我不想写入临时文件。我之所以尝试安装PIL,是因为我已经读过一些使用PIL图像库的人,但是一旦安装PIL,由于Pillow版本不兼容,我的另一部分代码就会中断。
答案1
小编典典pdfrw文档很烂
这个问题的第一个答案中讨论的pdfrw示例有点笨拙的唯一原因是因为pdfrw文档很烂。由于苏茨基文档,这个例子的作者@拉里-
Meyn用于rst2pdf的vectorpdf扩展为为出发点,而 该 扩展是不是真的记录或者, 并
具有处理rst2pdf的怪癖以及pdfrw(和更超出您的需要,因为它可以使rst2pdf从预先存在的PDF的arbitray页显示任意矩形)。Larry设法使它工作起来真是太神奇了,而我的帽子也给了他。
我完全有资格这么说,因为我是pdfrw的作者,并且对rst2pdf做出了一些贡献,其中包括vectorpdf扩展名。
但是您可能还是想使用pdfrw
直到一个月前,我才真正开始关注stackoverflow,而pdfrw本身却停滞了好几年,但我现在就在这里,我认为您应该重新看一下pdfrw,即使文档仍然很烂。
为什么? 因为如果输出到png文件,则图像将被 栅格化 ,如果使用pdfrw,则图像将保持 矢量格式 ,这意味着它在任何比例下都看起来不错。
所以我修改了您答案的png示例
您的png示例不是一个完整的程序-尚未定义doc.build的参数,未定义样式,缺少一些导入等。但是它足够接近以获得一些意图并获得它加工。
编辑 - _我刚刚注意到该示例实际上是Larry的示例的修改版本,因此该示例仍然非常有价值,因为在某些方面它比此功能更全。
解决这些问题并获得一些输出后,我添加了一个能够使用png或pdf的选项,因此您可以看到区别。下面的程序将创建两个不同的PDF文件,您可以自己比较结果。
import cStringIOfrom matplotlib import pyplot as pltfrom reportlab.pdfgen import canvasfrom reportlab.lib.utils import ImageReaderfrom reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Image, Flowablefrom reportlab.lib.units import inchfrom reportlab.lib.styles import getSampleStyleSheetfrom pdfrw import PdfReader, PdfDictfrom pdfrw.buildxobj import pagexobjfrom pdfrw.toreportlab import makerlstyles = getSampleStyleSheet()style = styles[''Normal'']def form_xo_reader(imgdata): page, = PdfReader(imgdata).pages return pagexobj(page)class PdfImage(Flowable): def __init__(self, img_data, width=200, height=200): self.img_width = width self.img_height = height self.img_data = img_data def wrap(self, width, height): return self.img_width, self.img_height def drawOn(self, canv, x, y, _sW=0): if _sW > 0 and hasattr(self, ''hAlign''): a = self.hAlign if a in (''CENTER'', ''CENTRE'', TA_CENTER): x += 0.5*_sW elif a in (''RIGHT'', TA_RIGHT): x += _sW elif a not in (''LEFT'', TA_LEFT): raise ValueError("Bad hAlign value " + str(a)) canv.saveState() img = self.img_data if isinstance(img, PdfDict): xscale = self.img_width / img.BBox[2] yscale = self.img_height / img.BBox[3] canv.translate(x, y) canv.scale(xscale, yscale) canv.doForm(makerl(canv, img)) else: canv.drawImage(img, x, y, self.img_width, self.img_height) canv.restoreState()def make_report(outfn, use_pdfrw): fig = plt.figure(figsize=(4, 3)) plt.plot([1,2,3,4],[1,4,9,26]) plt.ylabel(''some numbers'') imgdata = cStringIO.StringIO() fig.savefig(imgdata, format=''pdf'' if use_pdfrw else ''png'') imgdata.seek(0) reader = form_xo_reader if use_pdfrw else ImageReader image = reader(imgdata) doc = SimpleDocTemplate(outfn) style = styles["Normal"] story = [Spacer(0, inch)] img = PdfImage(image, width=200, height=200) for i in range(10): bogustext = ("Paragraph number %s. " % i) p = Paragraph(bogustext, style) story.append(p) story.append(Spacer(1,0.2*inch)) story.append(img) for i in range(10): bogustext = ("Paragraph number %s. " % i) p = Paragraph(bogustext, style) story.append(p) story.append(Spacer(1,0.2*inch)) doc.build(story)make_report("hello_png.pdf", False)make_report("hello_pdf.pdf", True)
这种方法有什么缺点?
第一个明显的缺点是,现在对pdfrw有要求,但是可以从PyPI获得。
下一个缺点是,如果您将大量matplotlib图放入文档中,我认为该技术将复制字体等资源,因为我认为reportlab不够聪明,无法注意到重复项。
我相信可以通过将所有图输出到单个PDF的不同页面来解决此问题。我实际上没有使用matplotlib尝试过,但是pdfrw完全能够将现有pdf的每一页转换为单独的flowable。
因此,如果您有很多图,并且使最终的PDF太大,则可以调查一下,或者只是尝试其中一种PDF优化器,看看是否有帮助。无论如何,在不同的日子里这是一个不同的问题。
4.1Python数据处理篇之Matplotlib系列(一)---初识Matplotlib
目录
[TOC]
前言
对于数据可视化的python库,对于Matplotlib早有耳闻,今天就来正式学习一下。
(一)matplotlib的介绍
matplotlib是python优秀的2D绘图库,可以完成大部分的绘图需求,同时其可定制性也很强,可内嵌在tkinter等各种GUI框架里。
官方网站:https://matplotlib.org/users/index.html
官方教程:https://matplotlib.org/tutorials/index.html
官方例子:https://matplotlib.org/gallery/index.html
(二)画一个简单的画布
==1.源代码==
import matplotlib.pyplot as plt
import numpy as np
# 在-1~1之间建立50个点
x = np.linspace(-1, 1, 50)
# y = 2*x + 1
y = x**2
# 创建画布
plt.plot(x, y)
# 展现画布
plt.show()
==2.展示效果==
(三)画布按键的功能介绍
==1.对于画布功能键的排序==
==(1)主页==
不管图片被你整成什么样,只要你按一下主页按钮,就会恢复到刚开始的样子。
==(2)上一个视图==
就是你改变了图片的位置,这个键就是跳到上一个键的图片位置。
==(3)下一个视图==
就是你改变了图片的位置,这个键就是跳到下一个键的图片位置。
==(4)移动查看==
我们可以以拖动的方式,来查看未显示的部分。
==(5)放大查看==
我们还可以用放大的方式,来细致的观察微小的部分。
==(6)窗体设置==
我们可以调整显示区域在窗体的显示位置。
==(7)保存图片==
我们可以把视图保存为图片。
作者:Mark
日期:2019/01/30 周三
Help on module matplotlib.cm in matplotlib:
Help on module matplotlib.cm in matplotlib:
NAME
matplotlib.cm
FILE
d:\programdata\anaconda2\lib\site-packages\matplotlib\cm.py
DESCRIPTION
This module provides a large set of colormaps, functions for
registering new colormaps and for getting a colormap by name,
and a mixin class for adding color mapping functionality.
CLASSES
__builtin__.object
ScalarMappable
class ScalarMappable(__builtin__.object)
| This is a mixin class to support scalar data to RGBA mapping.
| The ScalarMappable makes use of data normalization before returning
| RGBA colors from the given colormap.
|
| Methods defined here:
|
| __init__(self, norm=None, cmap=None)
| Parameters
| ----------
| norm : :class:`matplotlib.colors.Normalize` instance
| The normalizing object which scales data, typically into the
| interval ``[0, 1]``.
| If *None*, *norm* defaults to a *colors.Normalize* object which
| initializes its scaling based on the first data processed.
| cmap : str or :class:`~matplotlib.colors.Colormap` instance
| The colormap used to map normalized data values to RGBA colors.
|
| add_checker(self, checker)
| Add an entry to a dictionary of boolean flags
| that are set to True when the mappable is changed.
|
| autoscale(self)
| Autoscale the scalar limits on the norm instance using the
| current array
|
| autoscale_None(self)
| Autoscale the scalar limits on the norm instance using the
| current array, changing only limits that are None
|
| changed(self)
| Call this whenever the mappable is changed to notify all the
| callbackSM listeners to the ''changed'' signal
|
| check_update(self, checker)
| If mappable has changed since the last check,
| return True; else return False
|
| get_array(self)
| Return the array
|
| get_clim(self)
| return the min, max of the color limits for image scaling
|
| get_cmap(self)
| return the colormap
|
| set_array(self, A)
| Set the image array from numpy array *A*.
|
| ..
| ACCEPTS: ndarray
|
| Parameters
| ----------
| A : ndarray
|
| set_clim(self, vmin=None, vmax=None)
| set the norm limits for image scaling; if *vmin* is a length2
| sequence, interpret it as ``(vmin, vmax)`` which is used to
| support setp
|
| ACCEPTS: a length 2 sequence of floats
|
| set_cmap(self, cmap)
| set the colormap for luminance data
|
| ACCEPTS: a colormap or registered colormap name
|
| set_norm(self, norm)
| Set the normalization instance.
|
| ..
| ACCEPTS: `~.Normalize`
|
| Parameters
| ----------
| norm : `~.Normalize`
|
| to_rgba(self, x, alpha=None, bytes=False, norm=True)
| Return a normalized rgba array corresponding to *x*.
|
| In the normal case, *x* is a 1-D or 2-D sequence of scalars, and
| the corresponding ndarray of rgba values will be returned,
| based on the norm and colormap set for this ScalarMappable.
|
| There is one special case, for handling images that are already
| rgb or rgba, such as might have been read from an image file.
| If *x* is an ndarray with 3 dimensions,
| and the last dimension is either 3 or 4, then it will be
| treated as an rgb or rgba array, and no mapping will be done.
| The array can be uint8, or it can be floating point with
| values in the 0-1 range; otherwise a ValueError will be raised.
| If it is a masked array, the mask will be ignored.
| If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
| will be used to fill in the transparency. If the last dimension
| is 4, the *alpha* kwarg is ignored; it does not
| replace the pre-existing alpha. A ValueError will be raised
| if the third dimension is other than 3 or 4.
|
| In either case, if *bytes* is *False* (default), the rgba
| array will be floats in the 0-1 range; if it is *True*,
| the returned rgba array will be uint8 in the 0 to 255 range.
|
| If norm is False, no normalization of the input data is
| performed, and it is assumed to be in the range (0-1).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
get_cmap(name=None, lut=None)
Get a colormap instance, defaulting to rc values if *name* is None.
Colormaps added with :func:`register_cmap` take precedence over
built-in colormaps.
If *name* is a :class:`matplotlib.colors.Colormap` instance, it will be
returned.
If *lut* is not None it must be an integer giving the number of
entries desired in the lookup table, and *name* must be a standard
mpl colormap name.
register_cmap(name=None, cmap=None, data=None, lut=None)
Add a colormap to the set recognized by :func:`get_cmap`.
It can be used in two ways::
register_cmap(name=''swirly'', cmap=swirly_cmap)
register_cmap(name=''choppy'', data=choppydata, lut=128)
In the first case, *cmap* must be a :class:`matplotlib.colors.Colormap`
instance. The *name* is optional; if absent, the name will
be the :attr:`~matplotlib.colors.Colormap.name` attribute of the *cmap*.
In the second case, the three arguments are passed to
the :class:`~matplotlib.colors.LinearSegmentedColormap` initializer,
and the resulting colormap is registered.
revcmap(data)
Can only handle specification *data* in dictionary format.
DATA
Accent = <matplotlib.colors.ListedColormap object>
Accent_r = <matplotlib.colors.ListedColormap object>
Blues = <matplotlib.colors.LinearSegmentedColormap object>
Blues_r = <matplotlib.colors.LinearSegmentedColormap object>
BrBG = <matplotlib.colors.LinearSegmentedColormap object>
BrBG_r = <matplotlib.colors.LinearSegmentedColormap object>
BuGn = <matplotlib.colors.LinearSegmentedColormap object>
BuGn_r = <matplotlib.colors.LinearSegmentedColormap object>
BuPu = <matplotlib.colors.LinearSegmentedColormap object>
BuPu_r = <matplotlib.colors.LinearSegmentedColormap object>
CMRmap = <matplotlib.colors.LinearSegmentedColormap object>
CMRmap_r = <matplotlib.colors.LinearSegmentedColormap object>
Dark2 = <matplotlib.colors.ListedColormap object>
Dark2_r = <matplotlib.colors.ListedColormap object>
GnBu = <matplotlib.colors.LinearSegmentedColormap object>
GnBu_r = <matplotlib.colors.LinearSegmentedColormap object>
Greens = <matplotlib.colors.LinearSegmentedColormap object>
Greens_r = <matplotlib.colors.LinearSegmentedColormap object>
Greys = <matplotlib.colors.LinearSegmentedColormap object>
Greys_r = <matplotlib.colors.LinearSegmentedColormap object>
LUTSIZE = 256
OrRd = <matplotlib.colors.LinearSegmentedColormap object>
OrRd_r = <matplotlib.colors.LinearSegmentedColormap object>
Oranges = <matplotlib.colors.LinearSegmentedColormap object>
Oranges_r = <matplotlib.colors.LinearSegmentedColormap object>
PRGn = <matplotlib.colors.LinearSegmentedColormap object>
PRGn_r = <matplotlib.colors.LinearSegmentedColormap object>
Paired = <matplotlib.colors.ListedColormap object>
Paired_r = <matplotlib.colors.ListedColormap object>
Pastel1 = <matplotlib.colors.ListedColormap object>
Pastel1_r = <matplotlib.colors.ListedColormap object>
Pastel2 = <matplotlib.colors.ListedColormap object>
Pastel2_r = <matplotlib.colors.ListedColormap object>
PiYG = <matplotlib.colors.LinearSegmentedColormap object>
PiYG_r = <matplotlib.colors.LinearSegmentedColormap object>
PuBu = <matplotlib.colors.LinearSegmentedColormap object>
PuBuGn = <matplotlib.colors.LinearSegmentedColormap object>
PuBuGn_r = <matplotlib.colors.LinearSegmentedColormap object>
PuBu_r = <matplotlib.colors.LinearSegmentedColormap object>
PuOr = <matplotlib.colors.LinearSegmentedColormap object>
PuOr_r = <matplotlib.colors.LinearSegmentedColormap object>
PuRd = <matplotlib.colors.LinearSegmentedColormap object>
PuRd_r = <matplotlib.colors.LinearSegmentedColormap object>
Purples = <matplotlib.colors.LinearSegmentedColormap object>
Purples_r = <matplotlib.colors.LinearSegmentedColormap object>
RdBu = <matplotlib.colors.LinearSegmentedColormap object>
RdBu_r = <matplotlib.colors.LinearSegmentedColormap object>
RdGy = <matplotlib.colors.LinearSegmentedColormap object>
RdGy_r = <matplotlib.colors.LinearSegmentedColormap object>
RdPu = <matplotlib.colors.LinearSegmentedColormap object>
RdPu_r = <matplotlib.colors.LinearSegmentedColormap object>
RdYlBu = <matplotlib.colors.LinearSegmentedColormap object>
RdYlBu_r = <matplotlib.colors.LinearSegmentedColormap object>
RdYlGn = <matplotlib.colors.LinearSegmentedColormap object>
RdYlGn_r = <matplotlib.colors.LinearSegmentedColormap object>
Reds = <matplotlib.colors.LinearSegmentedColormap object>
Reds_r = <matplotlib.colors.LinearSegmentedColormap object>
Set1 = <matplotlib.colors.ListedColormap object>
Set1_r = <matplotlib.colors.ListedColormap object>
Set2 = <matplotlib.colors.ListedColormap object>
Set2_r = <matplotlib.colors.ListedColormap object>
Set3 = <matplotlib.colors.ListedColormap object>
Set3_r = <matplotlib.colors.ListedColormap object>
Spectral = <matplotlib.colors.LinearSegmentedColormap object>
Spectral_r = <matplotlib.colors.LinearSegmentedColormap object>
Vega10 = <matplotlib.colors.ListedColormap object>
Vega10_r = <matplotlib.colors.ListedColormap object>
Vega20 = <matplotlib.colors.ListedColormap object>
Vega20_r = <matplotlib.colors.ListedColormap object>
Vega20b = <matplotlib.colors.ListedColormap object>
Vega20b_r = <matplotlib.colors.ListedColormap object>
Vega20c = <matplotlib.colors.ListedColormap object>
Vega20c_r = <matplotlib.colors.ListedColormap object>
Wistia = <matplotlib.colors.LinearSegmentedColormap object>
Wistia_r = <matplotlib.colors.LinearSegmentedColormap object>
YlGn = <matplotlib.colors.LinearSegmentedColormap object>
YlGnBu = <matplotlib.colors.LinearSegmentedColormap object>
YlGnBu_r = <matplotlib.colors.LinearSegmentedColormap object>
YlGn_r = <matplotlib.colors.LinearSegmentedColormap object>
YlOrBr = <matplotlib.colors.LinearSegmentedColormap object>
YlOrBr_r = <matplotlib.colors.LinearSegmentedColormap object>
YlOrRd = <matplotlib.colors.LinearSegmentedColormap object>
YlOrRd_r = <matplotlib.colors.LinearSegmentedColormap object>
absolute_import = _Feature((2, 5, 0, ''alpha'', 1), (3, 0, 0, ''alpha'', 0...
afmhot = <matplotlib.colors.LinearSegmentedColormap object>
afmhot_r = <matplotlib.colors.LinearSegmentedColormap object>
autumn = <matplotlib.colors.LinearSegmentedColormap object>
autumn_r = <matplotlib.colors.LinearSegmentedColormap object>
binary = <matplotlib.colors.LinearSegmentedColormap object>
binary_r = <matplotlib.colors.LinearSegmentedColormap object>
bone = <matplotlib.colors.LinearSegmentedColormap object>
bone_r = <matplotlib.colors.LinearSegmentedColormap object>
brg = <matplotlib.colors.LinearSegmentedColormap object>
brg_r = <matplotlib.colors.LinearSegmentedColormap object>
bwr = <matplotlib.colors.LinearSegmentedColormap object>
bwr_r = <matplotlib.colors.LinearSegmentedColormap object>
cmap_d = {u''Spectral'': <matplotlib.colors.LinearSegmented...tlib.color...
cmapname = u''afmhot''
cmaps_listed = {''inferno'': <matplotlib.colors.ListedColormap object>, ...
cool = <matplotlib.colors.LinearSegmentedColormap object>
cool_r = <matplotlib.colors.LinearSegmentedColormap object>
coolwarm = <matplotlib.colors.LinearSegmentedColormap object>
coolwarm_r = <matplotlib.colors.LinearSegmentedColormap object>
copper = <matplotlib.colors.LinearSegmentedColormap object>
copper_r = <matplotlib.colors.LinearSegmentedColormap object>
cubehelix = <matplotlib.colors.LinearSegmentedColormap object>
cubehelix_r = <matplotlib.colors.LinearSegmentedColormap object>
datad = {u''Spectral'': ((0.6196078431372549, 0.0039215686...830>, u''red...
division = _Feature((2, 2, 0, ''alpha'', 2), (3, 0, 0, ''alpha'', 0), 8192...
flag = <matplotlib.colors.LinearSegmentedColormap object>
flag_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_earth = <matplotlib.colors.LinearSegmentedColormap object>
gist_earth_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_gray = <matplotlib.colors.LinearSegmentedColormap object>
gist_gray_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_heat = <matplotlib.colors.LinearSegmentedColormap object>
gist_heat_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_ncar = <matplotlib.colors.LinearSegmentedColormap object>
gist_ncar_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_rainbow = <matplotlib.colors.LinearSegmentedColormap object>
gist_rainbow_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_stern = <matplotlib.colors.LinearSegmentedColormap object>
gist_stern_r = <matplotlib.colors.LinearSegmentedColormap object>
gist_yarg = <matplotlib.colors.LinearSegmentedColormap object>
gist_yarg_r = <matplotlib.colors.LinearSegmentedColormap object>
gnuplot = <matplotlib.colors.LinearSegmentedColormap object>
gnuplot2 = <matplotlib.colors.LinearSegmentedColormap object>
gnuplot2_r = <matplotlib.colors.LinearSegmentedColormap object>
gnuplot_r = <matplotlib.colors.LinearSegmentedColormap object>
gray = <matplotlib.colors.LinearSegmentedColormap object>
gray_r = <matplotlib.colors.LinearSegmentedColormap object>
hot = <matplotlib.colors.LinearSegmentedColormap object>
hot_r = <matplotlib.colors.LinearSegmentedColormap object>
hsv = <matplotlib.colors.LinearSegmentedColormap object>
hsv_r = <matplotlib.colors.LinearSegmentedColormap object>
inferno = <matplotlib.colors.ListedColormap object>
inferno_r = <matplotlib.colors.ListedColormap object>
jet = <matplotlib.colors.LinearSegmentedColormap object>
jet_r = <matplotlib.colors.LinearSegmentedColormap object>
magma = <matplotlib.colors.ListedColormap object>
magma_r = <matplotlib.colors.ListedColormap object>
nipy_spectral = <matplotlib.colors.LinearSegmentedColormap object>
nipy_spectral_r = <matplotlib.colors.LinearSegmentedColormap object>
ocean = <matplotlib.colors.LinearSegmentedColormap object>
ocean_r = <matplotlib.colors.LinearSegmentedColormap object>
pink = <matplotlib.colors.LinearSegmentedColormap object>
pink_r = <matplotlib.colors.LinearSegmentedColormap object>
plasma = <matplotlib.colors.ListedColormap object>
plasma_r = <matplotlib.colors.ListedColormap object>
print_function = _Feature((2, 6, 0, ''alpha'', 2), (3, 0, 0, ''alpha'', 0)...
prism = <matplotlib.colors.LinearSegmentedColormap object>
prism_r = <matplotlib.colors.LinearSegmentedColormap object>
rainbow = <matplotlib.colors.LinearSegmentedColormap object>
rainbow_r = <matplotlib.colors.LinearSegmentedColormap object>
seismic = <matplotlib.colors.LinearSegmentedColormap object>
seismic_r = <matplotlib.colors.LinearSegmentedColormap object>
spectral = <matplotlib.colors.LinearSegmentedColormap object>
spectral_r = <matplotlib.colors.LinearSegmentedColormap object>
spring = <matplotlib.colors.LinearSegmentedColormap object>
spring_r = <matplotlib.colors.LinearSegmentedColormap object>
summer = <matplotlib.colors.LinearSegmentedColormap object>
summer_r = <matplotlib.colors.LinearSegmentedColormap object>
tab10 = <matplotlib.colors.ListedColormap object>
tab10_r = <matplotlib.colors.ListedColormap object>
tab20 = <matplotlib.colors.ListedColormap object>
tab20_r = <matplotlib.colors.ListedColormap object>
tab20b = <matplotlib.colors.ListedColormap object>
tab20b_r = <matplotlib.colors.ListedColormap object>
tab20c = <matplotlib.colors.ListedColormap object>
tab20c_r = <matplotlib.colors.ListedColormap object>
terrain = <matplotlib.colors.LinearSegmentedColormap object>
terrain_r = <matplotlib.colors.LinearSegmentedColormap object>
unicode_literals = _Feature((2, 6, 0, ''alpha'', 2), (3, 0, 0, ''alpha'', ...
viridis = <matplotlib.colors.ListedColormap object>
viridis_r = <matplotlib.colors.ListedColormap object>
winter = <matplotlib.colors.LinearSegmentedColormap object>
winter_r = <matplotlib.colors.LinearSegmentedColormap object>
import matplotlib.pyplot as plt出错
>>>import matplotlib.pyplot as plt
/usr/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn(''Matplotlib is building the font cache using fc-list. This may take a moment.'')
在第八讲中,导入这个模块出错
解决:
找到缓存目录 删除~/.cache/matplotlib下面的缓存
deleted ~/.cache/matplotlib/fontList.cache
但是,当我准备删的时候,再import matplotlib时时没有出错,
不知道具体的原因是什么
importError: DLL load failed when import matplotlib.pyplot as plt
importError: DLL load failed when import matplotlib.pyplot as plt
出现这种情况的原因, 大多是matplotlib的版本与python的版本 不兼容所致的. 所以解决办法就是: 先卸载 matplotlib, 然后重新安装之. 在anaconda3的环境里用pip工具进行.
(D:\Anaconda3) C:\Users\Administrator>pip3 uninstall matplotlib
...
(D:\Anaconda3) C:\Users\Administrator>pip3 install matplotlib
71% |███████████████████████ | 6.3MB 2.3MB/s
71% |███████████████████████ | 6.3MB 2.3MB/s
71% |███████████████████████ | 6.3MB 2.3MB/s
71% |███████████████████████ | 6.3MB 2.3MB/s
71% |███████████████████████ | 6.3MB 2.3MB/s
71% |███████████████████████ | 6.4MB 2.3MB/s
71% |███████████████████████ | 6.4MB 2.3MB/s
72% |███████████████████████ | 6.4MB 2.3MB/s
72% |███████████████████████ | 6.4MB 2.6MB/s
72% |███████████████████████ | 6.4MB 2.6MB/s
72% |███████████████████████ | 6.4MB 2.5MB/s
72% |███████████████████████ | 6.4MB 2.2MB/s
72% |███████████████████████ | 6.4MB 2.2MB/s
72% |███████████████████████ | 6.4MB 2.2MB/s
72% |███████████████████████ | 6.5MB 2.2MB/s
72% |███████████████████████▌ | 6.5MB 2.2MB/s
73% |███████████████████████▌ | 6.5MB 2.3MB/s
73% |███████████████████████▌ | 6.5MB 2.3MB/s
73% |███████████████████████▌ | 6.5MB 2.3MB/s
73% |███████████████████████▌ | 6.5MB 2.4MB/s
73% |███████████████████████▌ | 6.5MB 2.4MB/s
73% |███████████████████████▌ | 6.5MB 2.6MB/s
73% |███████████████████████▌ | 6.5MB 2.3MB/s
73% |███████████████████████▌ | 6.5MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.2MB/s
74% |████████████████████████ | 6.6MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.2MB/s
74% |████████████████████████ | 6.6MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.3MB/s
74% |████████████████████████ | 6.6MB 2.0MB/s
74% |████████████████████████ | 6.6MB 2.2MB/s
75% |████████████████████████ | 6.6MB 2.1MB/s
75% |████████████████████████ | 6.7MB 2.0MB/s
75% |████████████████████████ | 6.7MB 2.0MB/s
75% |████████████████████████ | 6.7MB 2.0MB/s
75% |████████████████████████ | 6.7MB 1.9MB/s
75% |████████████████████████ | 6.7MB 1.9MB/s
75% |████████████████████████ | 6.7MB 1.9MB/s
75% |████████████████████████ | 6.7MB 1.9MB/s
75% |████████████████████████ | 6.7MB 2.3MB/s
76% |████████████████████████▌ | 6.7MB 2.4MB/
76% |████████████████████████▌ | 6.7MB 2.0MB/
76% |████████████████████████▌ | 6.8MB 2.1MB/
76% |████████████████████████▌ | 6.8MB 2.2MB/
76% |████████████████████████▌ | 6.8MB 2.2MB/
76% |████████████████████████▌ | 6.8MB 2.0MB/
76% |████████████████████████▌ | 6.8MB 2.0MB/
76% |████████████████████████▌ | 6.8MB 1.9MB/
77% |████████████████████████▌ | 6.8MB 1.7MB/
77% |█████████████████████████ | 6.8MB 1.7MB/
77% |█████████████████████████ | 6.8MB 1.6MB/
77% |█████████████████████████ | 6.9MB 1.8MB/
77% |█████████████████████████ | 6.9MB 1.8MB/
77% |█████████████████████████ | 6.9MB 1.9MB/
77% |█████████████████████████ | 6.9MB 1.9MB/
77% |█████████████████████████ | 6.9MB 2.0MB/
77% |█████████████████████████ | 6.9MB 2.0MB/
78% |█████████████████████████ | 6.9MB 2.1MB/
78% |█████████████████████████ | 6.9MB 2.2MB/
78% |█████████████████████████ | 6.9MB 2.3MB/
78% |█████████████████████████ | 6.9MB 2.3MB/
78% |█████████████████████████ | 7.0MB 2.3MB/
78% |█████████████████████████ | 7.0MB 2.3MB/
78% |█████████████████████████ | 7.0MB 2.3MB/
78% |█████████████████████████ | 7.0MB 2.3MB/
78% |█████████████████████████ | 7.0MB 2.3MB/
79% |█████████████████████████ | 7.0MB 2.3MB/
79% |█████████████████████████▌ | 7.0MB 2.4MB
79% |█████████████████████████▌ | 7.0MB 2.4MB
79% |█████████████████████████▌ | 7.0MB 2.5MB
79% |█████████████████████████▌ | 7.0MB 2.6MB
79% |█████████████████████████▌ | 7.1MB 2.6MB
79% |█████████████████████████▌ | 7.1MB 2.6MB
79% |█████████████████████████▌ | 7.1MB 2.6MB
80% |█████████████████████████▌ | 7.1MB 2.6MB
80% |█████████████████████████▌ | 7.1MB 2.6MB
80% |██████████████████████████ | 7.1MB 2.6MB
80% |██████████████████████████ | 7.1MB 2.6MB
80% |██████████████████████████ | 7.1MB 2.3MB
80% |██████████████████████████ | 7.1MB 2.3MB
80% |██████████████████████████ | 7.1MB 2.3MB
80% |██████████████████████████ | 7.2MB 2.3MB
80% |██████████████████████████ | 7.2MB 2.4MB
81% |██████████████████████████ | 7.2MB 2.3MB
81% |██████████████████████████ | 7.2MB 2.3MB
81% |██████████████████████████ | 7.2MB 2.3MB
81% |██████████████████████████ | 7.2MB 2.3MB
81% |██████████████████████████ | 7.2MB 2.4MB
81% |██████████████████████████ | 7.2MB 2.7MB
81% |██████████████████████████ | 7.2MB 2.8MB
81% |██████████████████████████ | 7.2MB 2.7MB
81% |██████████████████████████ | 7.3MB 2.6MB
82% |██████████████████████████ | 7.3MB 2.4MB
82% |██████████████████████████ | 7.3MB 2.4MB
82% |██████████████████████████▌ | 7.3MB 2.3M
82% |██████████████████████████▌ | 7.3MB 2.3M
82% |██████████████████████████▌ | 7.3MB 2.3M
82% |██████████████████████████▌ | 7.3MB 2.3M
82% |██████████████████████████▌ | 7.3MB 2.4M
82% |██████████████████████████▌ | 7.3MB 2.3M
83% |██████████████████████████▌ | 7.4MB 2.3M
83% |██████████████████████████▌ | 7.4MB 2.4M
83% |██████████████████████████▌ | 7.4MB 2.5M
83% |███████████████████████████ | 7.4MB 2.5M
83% |███████████████████████████ | 7.4MB 2.5M
83% |███████████████████████████ | 7.4MB 2.1M
83% |███████████████████████████ | 7.4MB 2.1M
83% |███████████████████████████ | 7.4MB 2.1M
83% |███████████████████████████ | 7.4MB 2.1M
84% |███████████████████████████ | 7.4MB 2.1M
84% |███████████████████████████ | 7.5MB 1.8M
84% |███████████████████████████ | 7.5MB 1.8M
84% |███████████████████████████ | 7.5MB 1.8M
84% |███████████████████████████ | 7.5MB 1.6M
84% |███████████████████████████ | 7.5MB 1.6M
84% |███████████████████████████ | 7.5MB 1.8M
84% |███████████████████████████ | 7.5MB 1.8M
85% |███████████████████████████ | 7.5MB 1.8M
85% |███████████████████████████ | 7.5MB 1.7M
85% |███████████████████████████ | 7.5MB 1.5M
85% |███████████████████████████ | 7.6MB 1.8M
85% |███████████████████████████▌ | 7.6MB 1.7
85% |███████████████████████████▌ | 7.6MB 1.8
85% |███████████████████████████▌ | 7.6MB 2.0
85% |███████████████████████████▌ | 7.6MB 2.0
85% |███████████████████████████▌ | 7.6MB 1.8
86% |███████████████████████████▌ | 7.6MB 1.7
86% |███████████████████████████▌ | 7.6MB 1.8
86% |███████████████████████████▌ | 7.6MB 1.8
86% |███████████████████████████▌ | 7.6MB 1.9
86% |████████████████████████████ | 7.7MB 2.0
86% |████████████████████████████ | 7.7MB 2.0
86% |████████████████████████████ | 7.7MB 1.7
86% |████████████████████████████ | 7.7MB 1.8
86% |████████████████████████████ | 7.7MB 1.8
87% |████████████████████████████ | 7.7MB 2.0
87% |████████████████████████████ | 7.7MB 2.1
87% |████████████████████████████ | 7.7MB 2.1
87% |████████████████████████████ | 7.7MB 2.1
87% |████████████████████████████ | 7.8MB 2.2
87% |████████████████████████████ | 7.8MB 2.1
87% |████████████████████████████ | 7.8MB 1.9
87% |████████████████████████████ | 7.8MB 2.1
88% |████████████████████████████ | 7.8MB 2.2
88% |████████████████████████████ | 7.8MB 2.2
88% |████████████████████████████ | 7.8MB 2.2
88% |████████████████████████████ | 7.8MB 2.1
88% |████████████████████████████ | 7.8MB 2.1
88% |████████████████████████████▌ | 7.8MB 2.
88% |████████████████████████████▌ | 7.9MB 1.
88% |████████████████████████████▌ | 7.9MB 1.
88% |████████████████████████████▌ | 7.9MB 2.
89% |████████████████████████████▌ | 7.9MB 2.
89% |████████████████████████████▌ | 7.9MB 2.
89% |████████████████████████████▌ | 7.9MB 2.
89% |████████████████████████████▌ | 7.9MB 2.
89% |████████████████████████████▌ | 7.9MB 1.
89% |█████████████████████████████ | 7.9MB 1.
89% |█████████████████████████████ | 7.9MB 1.
89% |█████████████████████████████ | 8.0MB 2.
89% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
90% |█████████████████████████████ | 8.0MB 2.
91% |█████████████████████████████ | 8.1MB 2.
91% |█████████████████████████████ | 8.1MB 2.
91% |█████████████████████████████ | 8.1MB 2.
91% |█████████████████████████████ | 8.1MB 2.
91% |█████████████████████████████ | 8.1MB 1.
91% |█████████████████████████████ | 8.1MB 1.
91% |█████████████████████████████▌ | 8.1MB 2
91% |█████████████████████████████▌ | 8.1MB 2
91% |█████████████████████████████▌ | 8.1MB 2
92% |█████████████████████████████▌ | 8.2MB 2
92% |█████████████████████████████▌ | 8.2MB 2
92% |█████████████████████████████▌ | 8.2MB 1
92% |█████████████████████████████▌ | 8.2MB 1
92% |█████████████████████████████▌ | 8.2MB 1
92% |█████████████████████████████▌ | 8.2MB 2
92% |██████████████████████████████ | 8.2MB 2
92% |██████████████████████████████ | 8.2MB 1
92% |██████████████████████████████ | 8.2MB 1
93% |██████████████████████████████ | 8.2MB 1
93% |██████████████████████████████ | 8.3MB 1
93% |██████████████████████████████ | 8.3MB 2
93% |██████████████████████████████ | 8.3MB 2
93% |██████████████████████████████ | 8.3MB 2
93% |██████████████████████████████ | 8.3MB 2
93% |██████████████████████████████ | 8.3MB 1
93% |██████████████████████████████ | 8.3MB 1
94% |██████████████████████████████ | 8.3MB 2
94% |██████████████████████████████ | 8.3MB 2
94% |██████████████████████████████ | 8.3MB 2
94% |██████████████████████████████ | 8.4MB 2
94% |██████████████████████████████ | 8.4MB 2
94% |██████████████████████████████ | 8.4MB 2
94% |██████████████████████████████ | 8.4MB 2
94% |██████████████████████████████▌ | 8.4MB
94% |██████████████████████████████▌ | 8.4MB
95% |██████████████████████████████▌ | 8.4MB
95% |██████████████████████████████▌ | 8.4MB
95% |██████████████████████████████▌ | 8.4MB
95% |██████████████████████████████▌ | 8.4MB
95% |██████████████████████████████▌ | 8.5MB
95% |██████████████████████████████▌ | 8.5MB
95% |██████████████████████████████▌ | 8.5MB
95% |███████████████████████████████ | 8.5MB
95% |███████████████████████████████ | 8.5MB
96% |███████████████████████████████ | 8.5MB
96% |███████████████████████████████ | 8.5MB
96% |███████████████████████████████ | 8.5MB
96% |███████████████████████████████ | 8.5MB
96% |███████████████████████████████ | 8.6MB
96% |███████████████████████████████ | 8.6MB
96% |███████████████████████████████ | 8.6MB
96% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.6MB
97% |███████████████████████████████ | 8.7MB
97% |███████████████████████████████ | 8.7MB
97% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.7MB
98% |███████████████████████████████▌| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
99% |████████████████████████████████| 8.8MB
100% |████████████████████████████████| 8.9M
B 882kB/s Requirement already satisfied: cycler>=0.10 in d:\anaconda3\lib\site-packages (f rom matplotlib) (0.10.0) Collecting kiwisolver>=1.0.1 (from matplotlib) Downloading https://files.pythonhosted.org/packages/15/14/a7ae5a7d5fae78b40dd0 d388d83010330cba2df1721b1bd91a8b99044141/kiwisolver-1.1.0-cp36-none-win32.whl (4 4kB) 45% |██████████████▌ | 20kB 1.7MB/s eta 0:00: 68% |██████████████████████ | 30kB 1.8MB/s et 91% |█████████████████████████████ | 40kB 2.0 100% |████████████████████████████████| 51kB 1.2MB/s Requirement already satisfied: python-dateutil>=2.1 in d:\anaconda3\lib\site-pac kages (from matplotlib) (2.6.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in d:\an aconda3\lib\site-packages (from matplotlib) (2.2.0) Requirement already satisfied: numpy>=1.11 in d:\anaconda3\lib\site-packages (fr om matplotlib) (1.13.3) Requirement already satisfied: six in d:\anaconda3\lib\site-packages (from cycle r>=0.10->matplotlib) (1.11.0) Requirement already satisfied: setuptools in d:\anaconda3\lib\site-packages (fro m kiwisolver>=1.0.1->matplotlib) (36.5.0.post20170922) Installing collected packages: kiwisolver, matplotlib
Could not install packages due to an EnvironmentError:
[Errno 13] Permission denied: ''d:\anaconda3\Lib\site-packages\matplotlib\_image.cp36-win32.pyd''
Consider using the --user
option or check the permissions.
(D:\Anaconda3) C:\Users\Administrator>pip3 install --user matplotlib
Collecting matplotlib Using cached https://files.pythonhosted.org/packages/39/ae/60ec3ec8f8a18c5eef7 1c6dff7ed0dfa0cd2f2d57b6691e595e2bc43325f/matplotlib-3.1.1-cp36-cp36m-win32.whl Requirement already satisfied: cycler>=0.10 in d:\anaconda3\lib\site-packages (f rom matplotlib) (0.10.0) Requirement already satisfied: python-dateutil>=2.1 in d:\anaconda3\lib\site-pac kages (from matplotlib) (2.6.1) Requirement already satisfied: kiwisolver>=1.0.1 in d:\anaconda3\lib\site-packag es (from matplotlib) (1.1.0) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in d:\an aconda3\lib\site-packages (from matplotlib) (2.2.0) Requirement already satisfied: numpy>=1.11 in d:\anaconda3\lib\site-packages (fr om matplotlib) (1.13.3) Requirement already satisfied: six in d:\anaconda3\lib\site-packages (from cycle r>=0.10->matplotlib) (1.11.0) Requirement already satisfied: setuptools in d:\anaconda3\lib\site-packages (fro m kiwisolver>=1.0.1->matplotlib) (36.5.0.post20170922) Installing collected packages: matplotlib
Successfully installed matplotlib-3.1.1
(D:\Anaconda3) C:\Users\Administrator>
关于将matplotlib对象加载到reportlab中和matplotlib导入数据作图的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于4.1Python数据处理篇之Matplotlib系列(一)---初识Matplotlib、Help on module matplotlib.cm in matplotlib:、import matplotlib.pyplot as plt出错、importError: DLL load failed when import matplotlib.pyplot as plt的相关信息,请在本站寻找。
本文标签: