matplotlib.pyplot笔记

这篇笔记详细介绍了matplotlib.pyplot库,包括基本元素、折线图、直方图、饼图、条形图、散点图、子图等。内容涵盖轴设置、标记、颜色、样式、网格、图例、标题以及各种图形的实例和参数。
摘要由CSDN通过智能技术生成

matplotlib.pyplot Notebook

由于使用emacs-org进行编辑,为方便暂且使用英文

Table of Contents

  1. basic point
  2. basic elements
  3. line graph
    1. axis:
    2. line
      1. markers
      2. method 1
      3. method 2
      4. method 3
    3. legend, label and title
    4. grid
    5. get attributes
  4. histogram
    1. return
    2. instance
  5. pie chart
    1. instance
  6. bar graph
    1. instance
    2. distinguish between bar-graph and histogram
  7. scatter
    1. parameters
    2. instance
  8. subplot
    1. method subplot()
    2. method subplots()
      1. nrows, ncols:
      2. sharex, sharey:
      3. squeeze:
      4. return
      5. instance
  9. image
  10. fill
  11. stuffs
  12. colors
  13. xkcd-mode

basic point

hold: whether to hold all lines on same picture,
or del previous lines when drawing new ones

basic elements

axis: x, y, banners, scales, limits

gridline: .lw: linewidth, .alpha: alpha

line graph

axis:

# simply use axis()
plt.axis([0, 10, 0, 1])
# or use following methods
plt.xlim(0, 10)
plt.ylim(0, 1)

在这里插入图片描述

line

markers

  1. linestyles

    ’-’ solid line style

    ’–’ dashed line style

    ’-.’ dash-dot line style

    ’:’ dotted line style

  2. dot-markers

    ’.’ point marker

    ’,’ pixel marker

    ’o’ circle marker

    ’v’ triangle_down marker

    ’^’ triangle_up marker

    ’<’ triangle_left marker

    ’>’ triangle_right marker

    ’1’ tri_down marker

    ’2’ tri_up marker

    ’3’ tri_left marker

    ’4’ tri_right marker

    ’s’ square marker

    ’p’ pentagon marker

    ‘*’ star marker

    ’h’ hexagon1 marker

    ’H’ hexagon2 marker

    ’+’ plus marker

    ’x’ x marker

    ’D’ diamond marker

    ’d’ thin_diamond marker

    ’|’ vline marker

    ’_’ hline marker

  3. colors

    ’b’ blue

    ’r’ red

    ’g’ green

    ’c’ cyan

    ’m’ magenta

    ’y’ yellow

    ’w’ white

    ’k’ black

  4. linewidth

    (real number)

method 1

directly set in plot()

plt.plot(x, y, ',:m', linewidth = 0.2)
plt.plot(x, y, color = 'm', linestyle = ':', marker = ',',
               linewidth = 0.2)
plt.plot(x, y, color = 'magenta',
               linestyle = 'dotted',
               marker = 'pixel',
               linewidth = 0.2)

method 2

set with set()

line = plt.plot(range(5))[0]
line.set(color = 'm', linewidth = 0.2, )

method 3

set multiple lines with setp()

lines = plt.plot(range(5), range(8, 13))
plt.setp(lines, color = 'm', linewidth = 0.2, )

legend, label and title

remember to use legend() to activate labels

plt.plot(x, y, label = 'y = sinx')# set a legend
plt.legend()# activate

plt.xlabel('x axis')
plt.ylabel('y axis'
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值