简体   繁体   中英

How to spread out congested points on a plot (in matplotlib)?

The points on my graph are too tightly packed and I would like to spread them out but still follow the same pattern. I tried to use a step plot but it did not make any difference (see code below).

[...]
x = data1[:,0]
y = data1[:,1]

plt.figure(1)
plt.plot(x, y,'b.')
plt.title('normal plot')
plt.xlabel('x')
plt.ylabel('y')

plt.figure(2)
plt.step(x,y,'g.')
plt.title('plot with spread out points')
plt.xlabel('x')
plt.ylabel('y')

在此处输入图像描述

Link to my data

What am I missing in my code?

"Spread out" isn't very specific, but if you want to be able to distinguish between points more easily your best option is to change the markersize :

plt.scatter(x, y,'.b',ms=4)
plt.title('Scatter Plot')
plt.xlabel('x')
plt.ylabel('y')

From there since your data are gathered around the bottom of the plot you can examine those more closely by setting the limits to only focus on those "congested" points:

plt.ylim((0,50))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM