numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
用来制造散点
(在start和stop之间返回均匀间隔的数据)
(返回的是 [start, stop]之间的均匀分布)
(可以选择是否排除间隔的终点)
start:返回样本数据开始点
stop:返回样本数据结束点
num:生成的样本数据量,默认为50
endpoint:True则包含stop;False则不包含stop
retstep:即如果为True则结果会给出数据间隔)
dtype:输出数组类型
axis:0(默认)或-1
# 尽管在此用range与np.linspace等效, # 但scatter散点函数要求x y的长度一致时,np.linspace的优势就表现出现了, # 可以直接选择点的个数 # 同时实际用的时候np.linspace的报错率低 # 如在使用range时,x * 2 就会报错。 # TypeError: unsupported operand type(s) for *: 'range' and 'int' # x = range(1, 100, 2) x = np.linspace(1,100,50) y1 = x * 0.25 y2 = x * 0.5 y3 = x * 1 y4 = x * 2 d = np.linspace(1,10000,50) plt.figure('Scatter', facecolor='Thistle') plt.title('Scatter', fontsize=20) plt.xlabel('x', fontsize=14) plt.ylabel('y', fontsize=14) plt.tick_params(labelsize=10) plt.grid(linestyle=':') plt.scatter(x, y1, s=60, c=d, cmap='jet_r', alpha=0.5) plt.scatter(x, y2, s=60, c=d, cmap='jet', alpha=0.5) plt.scatter(x, y3, s=60, c=d, cmap='gray_r', alpha=0.5) plt.scatter(x, y4, s=60, c=d, cmap='gray', alpha=0.5) plt.show()

plt.tick_params()里面的参数设置两个坐标轴的刻度的大小
axis : {‘x’, ‘y’, ‘both’} Axis on which to operate; default is ‘both’. (axis:轴)
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
参数axis的值为’x’、’y’、’both’,分别代表设置X轴、Y轴以及同时设置,默认值为’both’。
ax1.tick_params(axis=’x’,width=2,colors=’gold’)
ax2.tick_params(axis=’y’,width=2,colors=’gold’)
ax3.tick_params(axis=’both’,width=2,colors=’gold’)

参数which的值为 ‘major’、’minor’、’both’,分别代表设置主刻度线、副刻度线以及同时设置,默认值为’major’ (主刻度线、副刻度线类似于厘米尺。CM与MM的区别)
ax1.tick_params(which=’major’,width=2,colors=’gold’)
ax2.tick_params(which=’minor’,width=2,colors=’gold’)
ax3.tick_params(which=’both’,width=2,colors=’gold’)

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

matplotlin.pyplot.grid(b, which, axis, color, linestyle, linewidth, **kwargs) b : 布尔值。就是是否显示网格线的意思。 which : 取值为'major', 'minor', 'both'。 默认为'major'。 axis : 取值为‘both’, ‘x’,‘y’。就是想绘制哪个方向的网格线。 color : 这就不用多说了,就是设置网格线的颜色。或者直接用c来代替color也可以。 linestyle :也可以用ls来代替linestyle, 设置网格线的风格,是连续实线,虚线或者其它不同的线条。 linewidth : 设置网格线的宽度
浙公网安备 33010602011771号