自定义matplotlib样式导入错误

时间:2018-04-03 12:36:20

标签: python matplotlib plot

我创建了自己的mplstyle,我想用标准方式导入它

import matplotlib.pylab as plt    
plt.style.use(path_to_file/name_of_file.mplstyle)

这是文件的内容:

_internal.classic_mode : False
agg.path.chunksize : 0
animation.avconv_args : []
animation.avconv_path : avconv
animation.bitrate : -1
animation.codec : h264
animation.convert_args : []
animation.convert_path : convert
animation.embed_limit : 20.0
animation.ffmpeg_args : []
animation.ffmpeg_path : ffmpeg
animation.frame_format : png
animation.html : none
animation.html_args : []
animation.writer : ffmpeg
axes.autolimit_mode : data
axes.axisbelow : True
axes.edgecolor : .15
axes.facecolor : white
axes.formatter.limits : -7, 7
axes.formatter.min_exponent : 0
axes.formatter.offset_threshold : 4
axes.formatter.use_locale : False
axes.formatter.use_mathtext : False
axes.formatter.useoffset : True
axes.grid : True
axes.grid.axis : both
axes.grid.which : major
axes.labelcolor : .15
axes.labelpad : 4.0
axes.labelsize : medium
axes.labelweight : normal
axes.linewidth : 1.0
axes.prop_cycle : cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])
axes.spines.bottom : True
axes.spines.left : True
axes.spines.right : True
axes.spines.top : True
axes.titlepad : 6.0
axes.titlesize : large
axes.titleweight : normal
axes.unicode_minus : True
axes.xmargin : 0.05
axes.ymargin : 0.05
axes3d.grid : True
backend.qt5 : PyQt5
boxplot.bootstrap : None
boxplot.boxprops.color : k
boxplot.boxprops.linestyle : -
boxplot.boxprops.linewidth : 1.0
boxplot.capprops.color : k
boxplot.capprops.linestyle : -
boxplot.capprops.linewidth : 1.0
boxplot.flierprops.color : k
boxplot.flierprops.linestyle : none
boxplot.flierprops.linewidth : 1.0
boxplot.flierprops.marker : o
boxplot.flierprops.markeredgecolor : k
boxplot.flierprops.markerfacecolor : none
boxplot.flierprops.markersize : 6.0
boxplot.meanline : False
boxplot.meanprops.color : C2
boxplot.meanprops.linestyle : --
boxplot.meanprops.linewidth : 1.0
boxplot.meanprops.marker : ^
boxplot.meanprops.markeredgecolor : C2
boxplot.meanprops.markerfacecolor : C2
boxplot.meanprops.markersize : 6.0
boxplot.medianprops.color : C1
boxplot.medianprops.linestyle : -
boxplot.medianprops.linewidth : 1.0
boxplot.notch : False
boxplot.patchartist : False
boxplot.showbox : True
boxplot.showcaps : True
boxplot.showfliers : True
boxplot.showmeans : False
boxplot.vertical : True
boxplot.whiskerprops.color : k
boxplot.whiskerprops.linestyle : -
boxplot.whiskerprops.linewidth : 1.0
boxplot.whiskers : 1.5
contour.corner_mask : True
contour.negative_linestyle : dashed
date.autoformatter.day : %Y-%m-%d
date.autoformatter.hour : %m-%d %H
date.autoformatter.microsecond : %M:%S.%f
date.autoformatter.minute : %d %H:%M
date.autoformatter.month : %Y-%m
date.autoformatter.second : %H:%M:%S
date.autoformatter.year : %Y
errorbar.capsize : 0.0
examples.directory :
figure.autolayout : False
figure.dpi : 72.0
figure.edgecolor : 1, 1, 1, 0
figure.facecolor : 1, 1, 1, 0
figure.figsize : 6.0, 4.0
figure.frameon : True
figure.subplot.bottom : 0.125
figure.subplot.hspace : 0.2
figure.subplot.left : 0.125
figure.subplot.right : 0.9
figure.subplot.top : 0.88
figure.subplot.wspace : 0.2
figure.titlesize : large
figure.titleweight : normal
font.cursive : Apple Chancery, Textile , Zapf Chancery, Sand, Script MT, Felipa, cursive
font.family : Quicksand
font.fantasy : Comic Sans MS, Chicago, Charcoal, ImpactWestern, Humor Sans, xkcd, fantasy]
font.monospace : DejaVu Sans Mono, Bitstream Vera Sans Mono, Computer Modern Typewriter, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
font.sans-serif : Arial, Liberation Sans, DejaVu Sans, Bitstream Vera Sans, sans-serif
font.serif : DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.size : 10.0
font.stretch : normal
font.style : normal
font.variant : normal
font.weight : bold
grid.alpha : 1.0
grid.color : .8
grid.linestyle : -
grid.linewidth : 0.8
hatch.color : k
hatch.linewidth : 1.0
hist.bins : 10
image.aspect : equal
image.cmap : Greys
image.composite_image : True
image.interpolation : nearest
image.lut : 256
image.origin : upper
image.resample : True
keymap.all_axes : a
keymap.back : left, c, backspace
keymap.forward : right, v
keymap.fullscreen : f, ctrl+f
keymap.grid : g
keymap.grid_minor : G
keymap.home : h, r, home
keymap.pan : p
keymap.quit : ctrl+w, cmd+w, q
keymap.quit_all : W, cmd+W, Q
keymap.save : s, ctrl+s
keymap.xscale : k, L
keymap.yscale : l
keymap.zoom : o
legend.borderaxespad : 0.5
legend.borderpad : 0.4
legend.columnspacing : 2.0
legend.edgecolor : 0.8
legend.facecolor : inherit
legend.fancybox : True
legend.fontsize : medium
legend.framealpha : 0.8
legend.frameon : False
legend.handleheight : 0.7
legend.handlelength : 2.0
legend.handletextpad : 0.8
legend.labelspacing : 0.5
legend.loc : best
legend.markerscale : 1.0
legend.numpoints : 1
legend.scatterpoints : 1
legend.shadow : False
lines.antialiased : True
lines.color : C0
lines.dash_capstyle : butt
lines.dash_joinstyle : round
lines.dashdot_pattern : 6.4, 1.6, 1.0, 1.6
lines.dashed_pattern : 3.7, 1.6
lines.dotted_pattern : 1.0, 1.65
lines.linestyle : -
lines.linewidth : 1.5
lines.marker : None
lines.markeredgewidth : 1.0
lines.markersize : 50.0
lines.scale_dashes : True
lines.solid_capstyle : round
lines.solid_joinstyle : round
markers.fillstyle : full
mathtext.bf : sans:bold
mathtext.cal : cursive
mathtext.default : it
mathtext.fallback_to_cm : True
mathtext.fontset : dejavusans
mathtext.it : sans:italic
mathtext.rm : sans
mathtext.sf : sans
mathtext.tt : monospace
patch.antialiased : True
patch.edgecolor : k
patch.facecolor : C0
patch.force_edgecolor : False
patch.linewidth : 1.0
path.effects : None
path.simplify : True
path.simplify_threshold : 0.111111111111
path.sketch : None
path.snap : True
pdf.compression : 6
pdf.fonttype : 3
pdf.inheritcolor : False
pdf.use14corefonts : False
pgf.debug : False
pgf.preamble : []
pgf.rcfonts : True
pgf.texsystem : xelatex
polaraxes.grid : True
ps.distiller.res : 6000
ps.fonttype : 3
ps.papersize : letter
ps.useafm : False
ps.usedistiller : False
savefig.bbox : tight
savefig.dpi : figure
savefig.edgecolor : w
savefig.facecolor : w
savefig.format : png
savefig.frameon : True
savefig.jpeg_quality : 95
savefig.orientation : portrait
savefig.pad_inches : 0.1
savefig.transparent : False
scatter.marker : o
svg.fonttype : path
svg.hashsalt : None
svg.image_inline : True
text.antialiased : True
text.color : .15
text.hinting : auto
text.hinting_factor : 8
text.latex.preamble :
text.latex.preview : False
text.latex.unicode : False
text.usetex : False
verbose.fileo : sys.stdout
verbose.level : silent
xtick.alignment : center
xtick.bottom : True
xtick.color : .15
xtick.direction : out
xtick.major.bottom : True
xtick.major.pad : 3.5
xtick.major.size : 6.0
xtick.major.top : True
xtick.major.width : 0.8
xtick.minor.bottom : True
xtick.minor.pad : 3.4
xtick.minor.size : 3.0
xtick.minor.top : True
xtick.minor.visible : False
xtick.minor.width : 0.6
xtick.top : False
ytick.alignment : center_baseline
ytick.color : .15
ytick.direction : out
ytick.labelsize : medium
ytick.left : True
ytick.major.left : True
ytick.major.pad : 3.5
ytick.major.right : True
ytick.major.size : 6.0
ytick.major.width : 0.8
ytick.minor.left : True
ytick.minor.pad : 3.4
ytick.minor.right : True
ytick.minor.size : 3.0
ytick.minor.visible : False
ytick.minor.width : 0.6
ytick.right : False

,错误是:

AttributeError                            Traceback (most recent call last)
~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    236 
    237     if 'png' in formats:
--> 238         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    239     if 'retina' in formats or 'png2x' in formats:
    240         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    120 
    121     bytes_io = BytesIO()
--> 122     fig.canvas.print_figure(bytes_io, **kw)
    123     data = bytes_io.getvalue()
    124     if fmt == 'svg':

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2214                     orientation=orientation,
   2215                     dryrun=True,
-> 2216                     **kwargs)
   2217                 renderer = self.figure._cachedRenderer
   2218                 bbox_inches = self.figure.get_tightbbox(renderer)

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    505 
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--> 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    428             # if toolbar:
    429             #     toolbar.set_cursor(cursors.WAIT)
--> 430             self.figure.draw(self.renderer)
    431         finally:
    432             # if toolbar:

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
   1294 
   1295             if self.frameon:
-> 1296                 self.patch.draw(renderer)
   1297 
   1298             mimage._draw_list_compositing_images(

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/patches.py in draw(self, renderer)
    542             renderer = PathEffectRenderer(self.get_path_effects(), renderer)
    543 
--> 544         renderer.draw_path(gc, tpath, affine, rgbFace)
    545 
    546         gc.restore()

~/miniconda3/envs/py36_anomaly_detection/lib/python3.6/site-packages/matplotlib/patheffects.py in draw_path(self, gc, tpath, affine, rgbFace)
    107     def draw_path(self, gc, tpath, affine, rgbFace=None):
    108         for path_effect in self._path_effects:
--> 109             path_effect.draw_path(self._renderer, gc, tpath, affine,
    110                                   rgbFace)
    111 

AttributeError: 'str' object has no attribute 'draw_path'<matplotlib.figure.Figure at 0x7fb9268cefd0>81.1

我通过打印plt.rcParams创建了mplstyle文件,然后手动编辑输出。这样做会创建必须删除的折旧变量,还需要从列表到字符串的转换。

1 个答案:

答案 0 :(得分:0)

您需要替换

path.effects : None

通过

path.effects :  

即。结肠后面没有任何东西。

一般来说,你的样式文件似乎只包含所有标准参数。您只需使用空文件即可实现相同目的。 如果要更改其中一些,只需将要更改的内容添加到文件中即可。

相关问题