孟灵己  

我现在觉得似乎matplotlib画出来的图更方便,更好看。而其是和ggplot2不一样的绘图的思路,所以我还是蛮想学习一下的。
我必须要有所进步才行。


Figure

fig = plt.figure() #没有坐标轴的空的图片
fig ,ax = plt.subplots() #一张图片 #这个一般比较常用
fig ,axs = plt.subplots(2,2) # 2×2方格的图片

Axes

这个概念容易和Axis混淆。在我的理解中,它的意思就是说“图中用于画图的那个区域”。Axes通常包括2-3个Axis的对象,提供ticks和tick labels来提供范围。
还可以设置标题,坐标的label以及其他。

Axis

这个指的就是坐标轴以及坐标轴的label。


上面是介绍了一张图所包含的整个的要素。
(我之前是不喜欢背东西,觉得能够查得到的东西干嘛要背呢,后来想想不行,我还是要行动起来,我还年轻,能够记得住,而且记得住让人觉得好像更加专业了一点。)

np.random.seed(19680801)  # seed the random number generator.
data = {'a': np.arange(50),
        'c': np.random.randint(0, 50, 50),
        'd': np.random.randn(50)}
data['b'] = data['a'] + 10 * np.random.randn(50)
data['d'] = np.abs(data['d']) * 100

fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
ax.scatter('a', 'b', c='c', s='d', data=data)
ax.set_xlabel('entry a')
ax.set_ylabel('entry b');

看了上面的代码,感觉整体上思路很简单。就是先构造一个data的对象(可以是一个matrix或array)。
然后再把这些数据“填”到如ax.scatter()的函数中。
最后再设定一下,title、label、legend即可。

posted on 2022-08-30 21:51  孟灵己  阅读(28)  评论(0编辑  收藏  举报