0

I do not want to use scatter as I am trying to overlay the line y=x on some unknown and weirdly scaled data.

plt.plot(xdata, ydata, "-ro")

Gives me a line with red dots on data points, is it possible to get different colour dots without having to use scatter?

Using the top answer from Adding y=x to a matplotlib scatter plot if I haven't kept track of all the data points that went in . My result is as follows: enter image description here

The images axes are squished and some points are not near in the full plot. MFE:

fig = plt.figure(figsize=(8,8))
graph = fig.add_subplot(111)
ax = graph.axes
small_x = [0.002, 0.04, 0.1, 0.005]
med_y = [25, 28, 24, 30, 12]
for val1, val2 in zip(small_x, med_y):
    graph.scatter(val1, val2)

lims = [
    np.min([ax.get_xlim(), ax.get_ylim()]),  # min of both axes
    np.max([ax.get_xlim(), ax.get_ylim()]),  # max of both axes
]

# now plot both limits against eachother
ax.plot(lims, lims, 'k-', alpha=0.75, zorder=0)
ax.set_aspect('equal')
ax.set_xlim(lims)
ax.set_ylim(lims)
plt.show()
Governor
  • 300
  • 1
  • 10
  • 1
    Can you give an example of your "unknown and weirdly scaled data"? It's unclear why `plt.scatter` wouldn't be appropriate (and I suspect you'll likely end up using it anyway) – asongtoruin Sep 12 '22 at 09:09
  • @asongtoruin see the edits above – Governor Sep 12 '22 at 09:15
  • 1
    You should look into how to create a [mcve]. But to quickly guess - you're using `ax.get_xlim()` and `ax.get_ylim()` when your x and y values seem to be of wildly different scales. Could your x-values be coming through as text? – asongtoruin Sep 12 '22 at 09:30
  • 1
    @asongtoruin ah they were coming through as strings, that fixed the axes but still the line y=x is disproportionately scaled to the points. See the MFE above. – Governor Sep 12 '22 at 09:40
  • 1
    Why do you think "y=x is disproportionately scaled" - your x values are significantly smaller than your y values – asongtoruin Sep 12 '22 at 10:04
  • @asongtoruin ah true - nevermind then – Governor Sep 12 '22 at 10:07

0 Answers0