简体   繁体   中英

Scatter plot change plot output when more scatters are added

A brief into on what i am working on. I am trying to make a plot from a scanned image. I have managed to turn the image to black and white and after that i made two csv files. The first one contains all the white values coordinates from the image (x,y) and the second file contains all the black coordinates. So the idea is that if i plot the the black coordinates i would get a similar plot like the image but with scatters.

Let me give some examples. Let's say that this is the black and white image 在此处输入图片说明

If i plot both black and white coordinates like that

fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.scatter(y, centered_y, s=0.5, c='r', marker='o', label='Background')
ax1.scatter(a, b, s=0.5, c='b', marker='o', label='black')
ax1 = plt.gca()
ax1.set_ylim(-300, 300)
ax1.set_xlim(0, 2000)
ax1.set_ylim(ax1.get_ylim()[::-1])
ax1.set_yticks(ticks=[-200, 0, 200])
ax1.set_xticks(ticks=[0, 1500, 2000])


i get a descent plot, which is quite close to the original image. 在此处输入图片说明

The problem that i have, is when i am trying to plot only one pair of scatter coordinates (either black coordinates or white coordinates). For example if i plot only the white coordinates i get this kind of plot (it is a bit zoomed in), which that too is quite close to the original image. 在此处输入图片说明 The problem is when i am tryng to plot only the black coordinates, i supposed that i would get the 'negative' of the previous plot as we can see in the blue and red graph (first plot). Unfortunatelly i get this : 在此处输入图片说明 and if i order the x axis i get this : 在此处输入图片说明 .

What i am trying to do is to connect the scatters of the black coordinates with a line so the plot to seems like the scanned image, but as i explained i can't get the right plot when i plot only the black coordinates.

After some time i found out that i was sorting only one of both axis.

The solution was to create a Dataframe and sort it on x axis. I was pretty silly :)

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