# 在 Matplotlib 中创建和更改标题位置

## 在 Matplotlib 中使用 `title()` 方法创建和更改标题位置

``````matplotlib.pyplot.title(label, fontdict=None, loc='center', pad=None, **kwargs)
``````

### `pad`

`pad` 参数是一个浮点值，允许我们更改标题与访问顶部的距离。如果没有值初始化，它将采用默认值 `6.0`

### `kwargs`

``````import matplotlib.pyplot as plot
# The x and y values (dependant an independent value)
plot.plot([12,24,36],[8,6,14])
plot.xlabel("X label")
plot.ylabel("Y label")
plot.title("First Example",{"size":20,"color":"blue"})
plot.show()
``````

`loc` 参数是标题的位置，用于传递左、中和右三个值。

``````import matplotlib.pyplot as plot
# The x and y values (dependant an independent value)
plot.plot([12,24,36],[8,6,14])
plot.xlabel("X label")
plot.ylabel("Y label")

# Create a title on left upper corner
plot.title("Second Example",{"size":20,"color":"blue"},loc="left")
plot.show()
``````

``````import matplotlib.pyplot as plot
# The x and y values (dependant an independent value)
plot.plot([12,24,36],[8,6,14])
plot.xlabel("X label")
plot.ylabel("Y label")
# Create a title on top left corner with 22 percent rotation
plot.show()
``````

`keyword` 参数与 `fontdict` 参数的工作方式相同，但 `keyword` 参数比 `fontdict` 参数具有更高的优先级，所以让我们看一个示例。

``````import matplotlib.pyplot as plot
# The x and y values (dependant an independent value)
plot.plot([12,24,36],[8,6,14])
plot.xlabel("X label")
plot.ylabel("Y label")
# Create a title on left upper corner with rotion of 22 % angle
plot.show()
``````

Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.