• matplotlib图表的样式


    网格线

    matplotlib.pyplot.grid(b=None, which='major', axis='both', )
    
    • 1
    • b:可选,默认为 None,可以设置布尔值,true 为显示网格线,false 为不显示,如果设置 **kwargs 参数,则值为 true。
    • which:可选,可选值有 ‘major’、‘minor’ 和 ‘both’,默认为 ‘major’,表示应用更改的网格线。
    • axis:可选,设置显示哪个方向的网格线,可以是取 ‘both’(默认),‘x’ 或 ‘y’,分别表示两个方向,x 轴方向或 y 轴方向。
    • **kwargs:可选,设置网格样式,可以是 color=‘r’, linestyle=‘-’ 和 linewidth=2,分别表示网格线的颜色,样式和宽度。

    设置字体及字体颜色

    plt.rcParams['font.family'] = "SimSun"  # 字体
    plt.rcParams['font.size'] = 60  # 字体大小
    plt.rcParams[‘font.sans-serif’]=[‘SimHei’]#显示中文标签 
    
    • 1
    • 2
    • 3

    显示正负号

    plt.rcParams[‘axes.unicode_minus’]=False
    
    • 1

    设置背景

    非绘图区背景

    fig.patch.set_facecolor('lightskyblue')
    fig.patch.set_alpha(0.6)  # set_alpha用于指定透明度
    
    • 1
    • 2

    设置背景图片:

    if __name__ == '__main__':
        fig = plt.figure(figsize=(16, 8))
        bgimg = img.imread('./world.png')
        fig.figimage(bgimg)
        pltfig(fig)
        plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    绘图区背景

    在ax中设定颜色

    ax.patch.set_facecolor('greenyellow')
    
    • 1

    设置背景图片:

    img = plt.imread("哆啦A梦.jpg")
    fig,ax = plt.subplots()
    ax.imshow(img)
    
    • 1
    • 2
    • 3

    ax.patch.set_alpha(0.0) 绘图本身的背景现在是透明的。

    字体

    黑体:SimHei
    微软雅黑:Microsoft YaHei
    微软正黑体:Microsoft JhengHei
    新宋体:NSimSun
    新细明体:PMingLiU
    细明体:MingLiU
    华文新魏:STXinwei
    华文行楷:STXingkai
    华文隶书:STLliti
    花纹琥珀:STHupo
    华文彩云:STCaiyun
    方正姚体:FZYaoti
    方正舒体:FZShuTi
    标楷体:DFKai-SB
    华文仿宋:STFangsong
    华文中宋:STZhongsong
    华文宋体:STSong
    华文楷体:STKaiti
    华文细黑:STXihei
    幼圆:YouYuan
    隶书:LiSu
    楷体_GB 2313:Kaiti_GB2313
    仿宋_GB2313:FangSong_GB2313
    仿宋:FangSong

    rcParams

    pyplot使用rcParams来自定义图形的各种默认属性,称之为运行配置参数。通过更改参数可以修改默认的属性,包括窗体大小、每英寸的点数、线条宽度、颜色、样式、坐标轴、坐标和网络属性、文本、字体等。

    • _internal.classic_mode
    • agg.path.chunksize
    • animation.bitrate
    • animation.codec
    • animation.convert_args
    • animation.convert_path
    • animation.embed_limit
    • animation.ffmpeg_args
    • animation.ffmpeg_path
    • animation.frame_format
    • animation.html
    • animation.writer
    • axes.autolimit_mode
    • axes.axisbelow
    • axes.edgecolor
    • axes.facecolor
    • axes.formatter.limits
    • axes.formatter.min_exponent
    • axes.formatter.offset_threshold
    • axes.formatter.use_locale
    • axes.formatter.use_mathtext
    • axes.formatter.useoffset
    • axes.grid
    • axes.grid.axis
    • axes.grid.which
    • axes.labelcolor
    • axes.labelpad
    • axes.labelsize
    • axes.labelweight
    • axes.linewidth
    • axes.prop_cycle
    • axes.spines.bottom
    • axes.spines.left
    • axes.spines.right
    • axes.spines.top
    • axes.titlecolor
    • axes.titlelocation
    • axes.titlepad
    • axes.titlesize
    • axes.titleweight
    • axes.titley
    • axes.unicode_minus
    • axes.xmargin
    • axes.ymargin
    • axes.zmargin
    • axes3d.grid
    • backend
    • backend_fallback
    • boxplot.bootstrap
    • boxplot.boxprops.color
    • boxplot.boxprops.linestyle
    • boxplot.boxprops.linewidth
    • boxplot.capprops.color
    • boxplot.capprops.linestyle
    • boxplot.capprops.linewidth
    • boxplot.flierprops.color
    • boxplot.flierprops.linestyle
    • boxplot.flierprops.linewidth
    • boxplot.flierprops.marker
    • boxplot.flierprops.markeredgecolor
    • boxplot.flierprops.markeredgewidth
    • boxplot.flierprops.markerfacecolor
    • boxplot.flierprops.markersize
    • boxplot.meanline
    • boxplot.meanprops.color
    • boxplot.meanprops.linestyle
    • boxplot.meanprops.linewidth
    • boxplot.meanprops.marker
    • boxplot.meanprops.markeredgecolor
    • boxplot.meanprops.markerfacecolor
    • boxplot.meanprops.markersize
    • boxplot.medianprops.color
    • boxplot.medianprops.linestyle
    • boxplot.medianprops.linewidth
    • boxplot.notch
    • boxplot.patchartist
    • boxplot.showbox
    • boxplot.showcaps
    • boxplot.showfliers
    • boxplot.showmeans
    • boxplot.vertical
    • boxplot.whiskerprops.color
    • boxplot.whiskerprops.linestyle
    • boxplot.whiskerprops.linewidth
    • boxplot.whiskers
    • contour.corner_mask
    • contour.linewidth
    • contour.negative_linestyle
    • date.autoformatter.day
    • date.autoformatter.hour
    • date.autoformatter.microsecond
    • date.autoformatter.minute
    • date.autoformatter.month
    • date.autoformatter.second
    • date.autoformatter.year
    • date.converter
    • date.epoch
    • date.interval_multiples
    • docstring.hardcopy
    • errorbar.capsize
    • figure.autolayout
    • figure.constrained_layout.h_pad
    • figure.constrained_layout.hspace
    • figure.constrained_layout.use
    • figure.constrained_layout.w_pad
    • figure.constrained_layout.wspace
    • figure.dpi
    • figure.edgecolor
    • figure.facecolor
    • figure.figsize
    • figure.frameon
    • figure.max_open_warning
    • figure.raise_window
    • figure.subplot.bottom
    • figure.subplot.hspace
    • figure.subplot.left
    • figure.subplot.right
    • figure.subplot.top
    • figure.subplot.wspace
    • figure.titlesize
    • figure.titleweight
    • font.cursive
    • font.family
    • font.fantasy
    • font.monospace
    • font.sans-serif
    • font.serif
    • font.size
    • font.stretch
    • font.style
    • font.variant
    • font.weight
    • grid.alpha
    • grid.color
    • grid.linestyle
    • grid.linewidth
    • hatch.color
    • hatch.linewidth
    • hist.bins
    • image.aspect
    • image.cmap
    • image.composite_image
    • image.interpolation
    • image.lut
    • image.origin
    • image.resample
    • interactive
    • keymap.back
    • keymap.copy
    • keymap.forward
    • keymap.fullscreen
    • keymap.grid
    • keymap.grid_minor
    • keymap.help
    • keymap.home
    • keymap.pan
    • keymap.quit
    • keymap.quit_all
    • keymap.save
    • keymap.xscale
    • keymap.yscale
    • keymap.zoom
    • legend.borderaxespad
    • legend.borderpad
    • legend.columnspacing
    • legend.edgecolor
    • legend.facecolor
    • legend.fancybox
    • legend.fontsize
    • legend.framealpha
    • legend.frameon
    • legend.handleheight
    • legend.handlelength
    • legend.handletextpad
    • legend.labelcolor
    • legend.labelspacing
    • legend.loc
    • legend.markerscale
    • legend.numpoints
    • legend.scatterpoints
    • legend.shadow
    • legend.title_fontsize
    • lines.antialiased
    • lines.color
    • lines.dash_capstyle
    • lines.dash_joinstyle
    • lines.dashdot_pattern
    • lines.dashed_pattern
    • lines.dotted_pattern
    • lines.linestyle
    • lines.linewidth
    • lines.marker
    • lines.markeredgecolor
    • lines.markeredgewidth
    • lines.markerfacecolor
    • lines.markersize
    • lines.scale_dashes
    • lines.solid_capstyle
    • lines.solid_joinstyle
    • markers.fillstyle
    • mathtext.bf
    • mathtext.cal
    • mathtext.default
    • mathtext.fallback
    • mathtext.fontset
    • mathtext.it
    • mathtext.rm
    • mathtext.sf
    • mathtext.tt
    • patch.antialiased
    • patch.edgecolor
    • patch.facecolor
    • patch.force_edgecolor
    • patch.linewidth
    • path.effects
    • path.simplify
    • path.simplify_threshold
    • path.sketch
    • path.snap
    • pcolor.shading
    • pcolormesh.snap
    • pdf.compression
    • pdf.fonttype
    • pdf.inheritcolor
    • pdf.use14corefonts
    • pgf.preamble
    • pgf.rcfonts
    • pgf.texsystem
    • polaraxes.grid
    • ps.distiller.res
    • ps.fonttype
    • ps.papersize
    • ps.useafm
    • ps.usedistiller
    • savefig.bbox
    • savefig.directory
    • savefig.dpi
    • savefig.edgecolor
    • savefig.facecolor
    • savefig.format
    • savefig.orientation
    • savefig.pad_inches
    • savefig.transparent
    • scatter.edgecolors
    • scatter.marker
    • svg.fonttype
    • svg.hashsalt
    • svg.image_inline
    • text.antialiased
    • text.color
    • text.hinting
    • text.hinting_factor
    • text.kerning_factor
    • text.latex.preamble
    • text.usetex
    • timezone
    • tk.window_focus
    • toolbar
    • webagg.address
    • webagg.open_in_browser
    • webagg.port
    • webagg.port_retries
    • xaxis.labellocation
    • xtick.alignment
    • xtick.bottom
    • xtick.color
    • xtick.direction
    • xtick.labelbottom
    • xtick.labelcolor
    • xtick.labelsize
    • xtick.labeltop
    • xtick.major.bottom
    • xtick.major.pad
    • xtick.major.size
    • xtick.major.top
    • xtick.major.width
    • xtick.minor.bottom
    • xtick.minor.pad
    • xtick.minor.size
    • xtick.minor.top
    • xtick.minor.visible
    • xtick.minor.width
    • xtick.top
    • yaxis.labellocation
    • ytick.alignment
    • ytick.color
    • ytick.direction
    • ytick.labelcolor
    • ytick.labelleft
    • ytick.labelright
    • ytick.labelsize
    • ytick.left
    • ytick.major.left
    • ytick.major.pad
    • ytick.major.right
    • ytick.major.size
    • ytick.major.width
    • ytick.minor.left
    • ytick.minor.pad
    • ytick.minor.right
    • ytick.minor.size
    • ytick.minor.visible
    • ytick.minor.width
    • ytick.right
  • 相关阅读:
    云原生之Kubernetes:7、Deployment控制器的更新机制
    消息队列-Kafka-基础架构
    mysql面试题1:MySQL有哪些常见存储引擎?MySQL默认是哪个存储引擎?
    spring配置文件第一行导致读取配置失败
    2023大数据挑战赛全国六强团队获奖经验+ppt分享(四)
    【数据结构】冒泡排序,快速排序的学习知识总结
    LeetCode-667. 优美的排列 II【数组,数学】
    Java编写简易rabbitmq生产者与消费者
    万字长文概述单目3D目标检测算法
    豪华低价不是国产新能源的“良药”
  • 原文地址:https://blog.csdn.net/weixin_43956958/article/details/126375509