数据可视化教程作业打卡-第四回:文字图例尽眉目

教程链接

https://github.com/datawhalechina/fantastic-matplotlib

https://gitee.com/zhang35/fantastic-matplotlib/blob/main/第四回:文字图例尽眉目.ipynb

作业

1.尝试在一张图中运用所讲过的功能,对title、text、xlable、ylabel、数学表达式、tick and ticklabel、legend进行详细的设计.

from matplotlib import pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']    # 指定默认字体为雅黑。

# 心形函数
x = np.linspace(-3.3**0.5, 3.3**0.5, 6001).reshape(-1,1)
y = (x**2)**(1/3) + 0.9*np.sqrt(3.3 - x**2)*np.sin(40*np.pi*x)
p0 = plt.plot(x,y,color = 'r')
plt.xlim(-3,3)

p1 = plt.plot([1,2,3])
plt.title('心')
plt.xlabel('X_label')
plt.ylabel('Y_label')
plt.legend(p0, 'h', loc='lower right')

plt.text(-0.5, 2.5, r'$E=mc^2$', fontsize=15)

# 使用axis的set_ticklabels方法手动设置标签格式的例子
ticks = np.arange(-3.0, 3.1, 0.5)
tickla = [f'{tick:1.2f}' for tick in ticks]
plt.xticks(ticks=ticks, labels=tickla, rotation=15)
plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值