matplotlitb1
应用
- 可以用来绘制各种静态,动态,交互式的图表
- 可以绘制线图、散点图、等高线图、条形图、柱状图、3D 图形、甚至是图形动画等等
API介绍
设置图片大小
fig = plt.figure(figsize=(宽, 高),dpi= )
x,y轴刻度大小
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import MultipleLocator
# 设置多个刻度范围
plt.figure(figsize=(10, 10))
ran = []
x = [1, 21, 23, 25, 60, 70]
y = [10, 20, 30, 40, 50, 60]
# 设置两个刻度范围
ran.extend(range(0, 30, 5))
ran.extend(range(30, 90, 10))
plt.xticks(ran, rotation=70,fontsize=10)
plt.yticks(range(0, 90, 10), fontsize=10)
plt.xlim(0, 80)
plt.ylim(0, 80)
plt.plot(x, y, color='green', marker='o', linestyle='dashed', linewidth=1, markersize=6)
plt.legend(["test"], loc="best")
plt.show()
设置横纵坐标的标签
plt.xlabel(), plt.ylabel()
#先在开头添加如下代码,防止中文乱码
import seaborn as sns
sns.set_style({
'font.sans-serif':['simhei','Arial']})
matplotlib.pyplot.xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
matplotlib.pyplot.ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
上述参数描述:
xlabel / ylabel: 字符串,横坐标标签,
fontdict: 将字体的属性存储在字典,传递给函数
c or color: 字体颜色
labelpad: 标签距离轴的长度,默认为4.0
fontfamily or family: 字体种类
fontsize or size:字体的大小, float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
fontweight or weigh: 字体的加粗程度 ,可选的值为{0-1000之间的数, ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’}
设置标题plt.title()
matplotlib.pyplot.title(label, fontdict=None, loc='center', pad=None