Python Forum
Learning matplotlib - axis not lining up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning matplotlib - axis not lining up
#1
Hi. I'm learning matplotlib and have an issue. I have a scatter plot working perfectly. I'm trying to draw lines between two points but it seems to be on a completely different axis scale. Why isn't the line being drawn between the two points specified?

import matplotlib.pyplot as plt

points = []
points.append((1, 2, 10,2))
points.append((10, 2, 1,200))
points.append((1, 200, 799,799))
points.append((150, 702, 142,221))
points.append((799, 799, 400, 400))
points.append((142, 221, 799, 799))
points.append((11, 562, 142, 221))
points.append((145, 255, 11, 562))
points.append((170, 702, 145, 255))
points.append((14, 52, 170, 702))
points.append((314, 35, 14, 52))
points.append((414, 52, 314, 352))
points.append((14, 452, 414, 52))
points.append((14, 552, 14, 452))
points.append((514, 52, 14, 552))
points.append((14, 652, 514, 52))
points.append((614, 52, 14, 652))
points.append((714, 752, 614, 52))
points.append((750, 712, 714, 752))
points.append((703, 742, 750, 712))
points.append((714, 772, 703, 742))
points.append((400,400, 714, 772))

gridpointsX = [200,200,200,400,400,400,600,600,600]
gridpointsY = [200,400,600,200,400,600,200,400,600]

xp = []
yp = []
for point in points:
  xp.append(point[0])
  yp.append(point[1])
  # plt.plot([point[0], point[1]], [point[2], point[3]])


plt.plot([400,400], [714,772])
# plt.grid(True, markevery=200)

plt.plot(xp, yp, 'bo')
plt.plot(gridpointsX, gridpointsY, "+", ms=10, zorder=-1, lw=.2)

plt.axis([0,800,0,800])
plt.show()
# savefig('plotted.png')
Reply
#2
Because it's supposed to be:
  plt.plot([point[0], point[2]], [point[1], point[3]])
[x1, x2],[y1, y2] not [x1, y1],[x2, y2]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  matplotlib x-axis text move bottom upward jacklee26 3 1,052 May-31-2023, 04:28 AM
Last Post: jacklee26
  x-axis labels with Matplotlib Mark17 8 2,297 Mar-23-2022, 06:10 PM
Last Post: Mark17
  How to make x-axis readable with matplotlib Mark17 7 4,015 Mar-01-2022, 04:30 PM
Last Post: DPaul
  matplotlib x axis range goes over the set range Pedroski55 5 3,286 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,483 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,824 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,287 Mar-11-2021, 10:52 AM
Last Post: buran
  matplotlib x-axis wrong order SchroedingersLion 4 4,322 Feb-23-2021, 05:42 PM
Last Post: nilamo
  Help with Matplotlib and ordering the axis theliberalguy97 3 8,204 Dec-12-2020, 08:06 PM
Last Post: deanhystad
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,515 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020