美文网首页
绘图的线型、颜色、标记

绘图的线型、颜色、标记

作者: 看远方的星 | 来源:发表于2023-01-18 23:41 被阅读0次
绘图:.plot()

plt.plot():绘制点和线[1]

from numpy.random import randn
plt.plot(randn(50).cumsum(),'k--')   # 生成50个正态分布的数
  • randn函数返回一个或一组样本,具有标准正态分布;
  • cumsum函数计算各行的累加值[2]
  • in:
import numpy as np
a = np.array([1,2,3,4,5,6])
a.cumsum()
  • out:
array([ 1, 3, 6, 10, 15, 21])

k-- 是线性选项,指定黑色虚线;

颜色(color),标记(marker),线型(linestyle)

指定绿色虚线:

ax.plot(x,y,'g--')  # 一样的效果,更简洁
ax.plot(x,y,linestyle='--',color='g')

指定黑色虚线,标记类型:

plt.plot(randn(50).cumsum(),'ko--')
plt.plot(randn(50).cumsum(),color='k',linestyle='dashed',marker='o')

用字符串指定时,颜色一定在最前面,可规范顺序:color+marker+line style

Color[3]

Long Name Short Name RGB Triplet
blue b [0,0,1]
black k [0,0,0]
red r [1,0,0]
green g [0,1,0]
yellow y [1,1,0]
cyan c [0,1,1]
magenta m [1,0,1]
white w [1,1,1]

Marker[4]

Marker Description Resulting Marker
"o" Circle
"+" Plus sign
"*" Asterisk
"." Point
"x" Cross
"_" Horizontal line
" | " Vertical line
"square" Square
"diamond" Diamond
"^" Upward-pointing triangle
"v" Downward-pointing triangle
">" Right-pointing triangle
"<" Left-pointing triangle
"pentagram" Pentagram
"hexagram" Hexagram

Line Style[4]

Line Style Description Resulting Line
"-" Solid line
"- -" Dashed line
":" Dotted line
"-." Dash-dotted line

Draw Style:在线型图中,可按非线性插值;

plt.plot(randn(50),'ko--',drawstyle='steps-post',label='steps-post')  
plt.legend(loc="best")  # 给图像加图例
image

目前有三种可选:steps、steps-mid、steps-post 具体差别还待探究;

image
该图出处:https://matplotlib.org/stable/gallery/lines_bars_and_markers/step_demo.html
  1. https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot

  2. https://blog.csdn.net/banana1006034246/article/details/78841461

  3. http://math.loyola.edu/~loberbro/matlab/html/colorsInMatlab.html

  4. https://www.mathworks.com/help/matlab/creating_plots/specify-line-and-marker-appearance-in-plots.html

相关文章

网友评论

      本文标题:绘图的线型、颜色、标记

      本文链接:https://www.haomeiwen.com/subject/sxwfhdtx.html