matplotlib 如何调整散点标记的点大小[复制]

mm9b1k5b  于 2023-11-22  发布在  其他
关注(0)|答案(1)|浏览(138)

此问题在此处已有答案

pyplot scatter plot marker size(7个答案)
18天前关门了。
有谁知道如何调整坐标系中的点的大小。此外,如果可以使用小十字代替点来显示点,那就太好了。

import numpy as np                 
import matplotlib.pyplot as plt    

# Enter x and y coordinates of points and colors
xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
ys = [64, 72, 47, 38, 55, 30, 47, 64, 73, 30, 55, 64, 38, 47, 73, 55, 38, 30, 72, 47, 63, 73, 47, 44, 38, 55, 30, 38, 55, 72, 47, 38, 65, 47, 38, 63, 30, 55, 72, 55, 47, 53, 73, 30, 38, 55, 30, 38, 64, 73]
colors = ['g']

# Select length of axes and the space between tick labels
xmin, xmax, ymin, ymax = 0, 50, 0, 80
ticks_frequency = 5

# Plot points
fig, ax = plt.subplots(figsize=(10, 10))
ax.scatter(xs, ys, c=colors)

# Set identical scales for both axes
ax.set(xlim=(xmin-1, xmax+1), ylim=(ymin-1, ymax+1), aspect='equal')

# Remove top and right spines
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

# Create 'x' and 'y' labels placed at the end of the axes
ax.set_xlabel('n', size=14, labelpad=-24, x=1.03)
ax.set_ylabel('t in s', size=14, labelpad=-21, y=1.02, rotation=0)

# Create custom major ticks to determine position of tick labels
x_ticks = np.arange(xmin, xmax+1, ticks_frequency)
y_ticks = np.arange(ymin, ymax+1, ticks_frequency)
ax.set_xticks(x_ticks[x_ticks != 0])
ax.set_yticks(y_ticks[y_ticks != 0])

# Create minor ticks placed at each integer to enable drawing of minor grid
# lines: note that this has no effect in this example with ticks_frequency=1
ax.set_xticks(np.arange(xmin, xmax+1), minor=True)
ax.set_yticks(np.arange(ymin, ymax+1), minor=True)

# Draw major and minor grid lines
ax.grid(which='both', color='grey', linewidth=1, linestyle='-', alpha=0.2)


plt.show()

字符串

72qzrwbm

72qzrwbm1#

您需要为绘图参数指定不同的markermarkersize

ax.scatter(xs, ys, c=colors, marker='x', s=5) #may need to fiddle with the s value to get what you want (not that it's the area of the marker, not its linear size)

字符串
请参阅https://matplotlib.org/stable/api/markers_api.html所有可用的标记,有很多。

相关问题