Matplotlib string for a variable plotted scattergram

Key Points

When drawing the scattergram, it is generally used as a carrier for the variable input data.
In fact, the string may be used as input data storage carrier.

The following code data = {“a”: x, “b”: y, “color”: c, “size”: s}is input to the scattergram data, color and markings on the size of the data dictionary data as a key-value pair corresponding to the key is a string string.

Matplotlib programming

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca()

x = np.random.rand(50)*10
y = np.random.rand(50)*10+20
s = np.random.rand(50)*100
c = np.random.rand(50)

data = {"a": x, "b": y, "color": c, "size": s}

# with the "data" keyboard argument
ax.scatter("a", "b", c="color", s="size", data=data)

ax.set(xlabel="X", ylabel="Y")

plt.show()

Finished map

Here Insert Picture Description

Published 515 original articles · won praise 1014 · Views 210,000 +

Guess you like

Origin blog.csdn.net/weixin_43896318/article/details/104335581