Matplotlib detailed tutorial [4] Drawing of scatter plots and fan plots and their style settings

Table of contents

Preface

Matplotlib draws scatter plot

Matplotlib draws fan chart

Epilogue


Preface

Overview of this article: Many Matplotlib tutorials on CSDN are not very well written. Many of them directly paste a bunch of code, and the comments are unclear and incomplete, which makes many readers who want to learn Matplotlib have a very poor experience, so the author intends to Write a series of Matplotlib tutorials to help newbies get started, and veterans can also check for gaps and fill in the gaps.

Author's introduction: The author is an artificial intelligence alchemist. Currently, the main research direction in the laboratory is generative models. He also has some knowledge of other directions. He hopes to communicate with friends who are also interested in artificial intelligence on the CSDN platform. Share and make progress together. Thank you everyone~~~

 如果你觉得这篇文章对您有帮助,麻烦点赞、收藏或者评论一下,这是对作者工作的肯定和鼓励。  

Matplotlib draws scatter plot

import matplotlib.pyplot as plt
import numpy as np
n=256
x=np.random.normal(0,1,n)
y=np.random.normal(0,1,n)
C=np.arctan2(x,y)
plt.scatter(x,y,s=75,c=C,alpha=0.5,marker='*')
plt.show()

s is the size of the point, c is the color of each point, alpha is the transparency of the point, and marker is the shape of the point

 

Matplotlib draws fan chart

import matplotlib.pyplot as plt
import numpy as np

x = np.array([40, 25, 25, 10])
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 解决中文乱码问题
plt.pie(x,
        labels=['猪肉', '白菜', '番茄', '羊肉'],  # 设置饼图标签
        colors=["darkred", "darkblue", "green", "orange"],  # 设置饼图颜色
        explode=(0.2, 0, 0, 0),  # 第一部分突出显示
        autopct='%.2f%%',  # 格式化输出百分比
        )
plt.title("食物购买情况")
plt.show()

Epilogue

 如果您觉得这篇文章对您有帮忙,请点赞、收藏。您的点赞是对作者工作的肯定和鼓励,这对作者来说真的非常重要。如果您对文章内容有任何疑惑和建议,欢迎在评论区里面进行评论,我将第一时间进行回复。 

Guess you like

Origin blog.csdn.net/qq_35768355/article/details/132656307