如何获取matplotlib.pyplot.scatter的默认蓝色?
散点图的默认颜色是蓝色。要获取 matplotlib 散点图的默认蓝色,我们可以使用 **annotate()** 方法对其进行注释。
步骤
- 使用 **subplots()** 方法创建一个图形和一组子图。
- 在 (-1, 1) 位置绘制一个散点。
- 为该点添加一些标签。
- 在 (-0.9, 1) 位置绘制一个散点。
- 为该点添加一些标签。
- 在 (1.9, 1) 位置绘制一个散点。
- 为该点添加一些标签。
- 使用 xlim 和 ylim 方法缩放 x 轴和 y 轴。
- 要显示图形,请使用 **show()** 方法。
示例
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
ax.scatter(-1, 1)
ax.annotate("default color", xy=(-0.9, 1))
ax.scatter(1, 1, c='#1f77b4')
ax.annotate("using hex", xy=(1.1, 1))
ax.set_xlim(-2, 3)
ax.set_ylim(-1, 2)
plt.show()输出

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP