zoukankan      html  css  js  c++  java
  • 初接触matplotlib

    1,绘制简单的折线图。

    1 import matplotlib.pyplot as plt
    2 
    3 square = [1,4,9,16,25]
    4 
    5 plt.plot(square)
    6 plt.show()

    2,使用matplotlib修改折现图的标签文字和线条粗细。

     1 '''修改标签文字和线图粗细'''
     2 import matplotlib.pyplot as plt
     3 
     4 square = [1,4,9,16,25]
     5 
     6 plt.plot(square,linewidth=5) #绘制折线,线条粗细为5
     7 plt.title("Square Numbers",fontsize=30) #设置标题,字体大小为30
     8 plt.xlabel("Values",fontsize=20) #设置x轴标签,字体大小为20
     9 plt.ylabel("Square of Value",fontsize=20) #设置y轴标签,字体大小为20
    10 plt.tick_params(axis='both',labelsize=10) #设置x轴和y轴的刻度标签字体大小为10,
    11 
    12 plt.show()

    3,校正折现图的起点从(1,1)开始。

     1 '''校正折线图的起点从(1,1)开始'''
     2 import matplotlib.pyplot as plt
     3 
     4 input_values = [1,2,3,4,5]
     5 square = [1,4,9,16,25]
     6 
     7 plt.plot(input_values,square,linewidth=5) #绘制折线,线条粗细为5
     8 plt.title("Square Numbers",fontsize=30) #设置标题,字体大小为30
     9 plt.xlabel("Values",fontsize=20) #设置x轴标签,字体大小为20
    10 plt.ylabel("Square of Values",fontsize=20) #设置y轴标签,字体大小为20
    11 plt.tick_params=(axis='both',labelsize=10) #设置x轴和y轴的刻度标签字体大小为10,
    12 
    13 plt.show()

    4,关于tick _params参数:

    Axes.tick_params(axis='both', **kwargs)

    参数:

    axis : {‘x’, ‘y’, ‘both’} Axis on which to operate; default is ‘both’.
    reset : bool If True, set all parameters to defaults before processing other keyword arguments. Default is False.
    which : {‘major’, ‘minor’, ‘both’} Default is ‘major’; apply arguments to which ticks.
    direction : {‘in’, ‘out’, ‘inout’} Puts ticks inside the axes, outside the axes, or both.
    length : float Tick length in points.
    width : float Tick width in points.
    color : color Tick color; accepts any mpl color spec.
    pad : float Distance in points between tick and label.
    labelsize : float or str Tick label font size in points or as a string (e.g., ‘large’).
    labelcolor : color Tick label color; mpl color spec.
    colors : color Changes the tick color and the label color to the same value: mpl color spec.
    zorder : float Tick and label zorder.
    bottom, top, left, right : bool or {‘on’, ‘off’} controls whether to draw the respective ticks.
    labelbottom, labeltop, labelleft, labelright : bool or {‘on’, ‘off’} controls whether to draw the respective tick labels.
    labelrotation : float Tick label rotation

    4.1,参数axis的值为'x'、'y'、'both',分别代表设置X轴、Y轴以及同时设置,默认值为'both';

    4.2,参数which的值为 'major'、'minor'、'both',分别代表设置主刻度线、副刻度线以及同时设置,默认值为'major';

    4.3,参数direction的值为'in'、'out'、'inout',分别代表刻度线显示在绘图区内侧、外侧以及同时显示;

    4.4,参数length和width分别用于设置刻度线的长度和宽度;

    4.5,参数pad用于设置刻度线与标签间的距离;

    4.6,参数color、labelcolor、colors分别用于设置刻度线的颜色、刻度线标签的颜色以及同时设置刻度线及标签颜色;

    4.7,参数labelsize用于设置刻度线标签的字体大小;

    4.8,参数bottom, top, left, right的值为布尔值,分别代表设置绘图区四个边框线上的的刻度线是否显示;

    4.9,参数labelbottom, labeltop, labelleft, labelright的值为布尔值,分别代表设置绘图区四个边框线上的刻度线标签是否显示;

  • 相关阅读:
    架构漫谈-阅读笔记(一)
    一线架构师实践指南--总结
    周四进度二
    质量属性改进
    结对作业第一次
    软件工程(2019)第三次作业
    软件工程(2019)第二次作业
    MarkDown编辑方法网址
    软件工程(2019年)第一次作业
    本人的coding地址
  • 原文地址:https://www.cnblogs.com/mafu/p/12915027.html
Copyright © 2011-2022 走看看