当前位置:网站首页>数据分析 - matplotlib示例代码
数据分析 - matplotlib示例代码
2022-07-02 09:41:00 【yinshuilan】
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2, 2, 100)
y1 = np.cos(np.pi * x)
y2 = np.sin(np.pi * x)
plt.plot(x, y1, "go", label=r"$y1=\cos(\pi \times x)$", alpha=0.8, linewidth=0.7)
plt.plot(x, y2, "r-", label=r"$y2=\sin(\pi \times x)$", alpha=0.8, linewidth=0.7)
df = pd.DataFrame(np.random.randint(0, 100, size=(100, 1)), columns=list('A'))
plt.annotate("important Point", (0, 1), xytext=(-1.5, 1.1), arrowprops=dict(arrowstyle='->'))
plt.xlabel("x-axis")
plt.ylabel("y-axis")
# 设置坐标范围[xmin, xmax, ymin, ymax]
plt.axis([-2.1, 2.1, -1.2, 1.2])
# 显示标签
plt.legend()
# 显示网格
plt.grid(alpha=0.4)
plt.title("Two Plots", color=(0.1, 0.3, 0.5))
plt.show()运行输入如下图:

import matplotlib as mpl
mpl.rcParams["font.sans-serif"] = ["Microsoft YaHei"]
mpl.rcParams['axes.unicode_minus'] = False对于Ubuntu系统,需要手动指定字体来实现中文的显示。 设置代码如下。

边栏推荐
- Basic usage of MySQL in centos8
- Jenkins installation
- 【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- 【云原生】2.5 Kubernetes 核心实战(下)
- 6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
- MySQL linked list data storage query sorting problem
- Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
- Fabric.js 3个api设置画布宽高
- 对毕业季即将踏入职场的年轻人的一点建议
猜你喜欢
随机推荐
基于Hardhat编写合约测试用例
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
预言机链上链下调研
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
基于Hardhat和Openzeppelin开发可升级合约(二)
MySQL比较运算符IN问题求解
Mmrotate rotation target detection framework usage record
GGPlot Examples Best Reference
webauthn——官方开发文档
亚马逊云科技 Community Builder 申请窗口开启
MTK full dump grab
How to Create a Beautiful Plots in R with Summary Statistics Labels
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
A white hole formed by antineutrons produced by particle accelerators
Map set assignment to database
R HISTOGRAM EXAMPLE QUICK REFERENCE
Astparser parsing class files with enum enumeration methods
[idea] use the plug-in to reverse generate code with one click
MySQL stored procedure cursor traversal result set









