Python Forum
matplotlib creating a scatter plot via PathCollection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matplotlib creating a scatter plot via PathCollection
#1
Hi there, first post here.
I'm trying to dig deeper into matplotlib and learn how it works under the cover. So I thought it'd be a simple task to draw a few points on the canvas and connect them with some lines. I was wrong. I looked at the source code for Axes.scatter. So I wrote the following code:
fig = plt.figure()
ax = fig.add_axes((0,0,1,1), frameon = True, xlim = (0,1), ylim = (0,1), xticks=[0.2], yticks=[0.2])
pos = [(0.2, 0.2), (0.2, 0.3), (0.3, 0.4), (0.4, 0.4), (0.5, 0.3), (0.5, 0.2), (0.35, 0.1)]
pp = Polygon([(0,0), (0.02, 0.02), (0.04, 0)])
#mypath = pp.get_path()
mypath = pp.get_path().transformed(pp.get_transform()) #*
dots = collections.PathCollection(paths = (mypath,), offsets= pos)
#dots.set_transform(transforms.IdentityTransform()).    #**
ax.add_collection(dots)
plt.show()
I expected that this would render 5 triangles in my canvas. But this only drew 1 triangle at the bottom left corner of the canvas. Substituting the line marked with * with the line above it doesn't change anything. Adding line marked with ** causes the single triangle to vanish too.
Can anyone tell me how I can achieve my goal? Sorry if this is the wrong forum; it seems matplotlib is mostly used for data-science.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pick a line in a plot with matplotlib Romain 3 5,546 Feb-28-2023, 11:56 AM
Last Post: get2sid
  Matplotlib scatter plot in loop with None values ivan_sc 1 2,234 Nov-04-2021, 11:25 PM
Last Post: jefsummers
  Matplotlib scatter plot slider with datetime sonny 0 2,918 Feb-05-2021, 02:31 AM
Last Post: sonny
  New to Python & Matplotlib - can I change the plot grid origin to lower left corner? FortyTwo 1 6,095 Aug-22-2020, 08:22 PM
Last Post: matador
  How to add lables to the scatter plot? Jack_Sparrow 3 3,224 Dec-11-2019, 10:20 PM
Last Post: Larz60+
  How to create correct scatter plot for PCA? LK91 0 2,069 Dec-11-2019, 07:53 PM
Last Post: LK91
  It doesn't show scatter plot but it says: "<Figure size 640x480 with 1 Axes>" dcardonaa 0 3,457 Oct-10-2019, 02:34 AM
Last Post: dcardonaa
  MatPlotLib 2d plot of current density? ruben 0 2,171 May-13-2019, 06:47 AM
Last Post: ruben
  Bar Plot with Python ,matplotlib and sqlite3 tables gauravbhardwajee 0 4,928 Sep-25-2018, 06:17 PM
Last Post: gauravbhardwajee
  Draw a square-aspect log-linear plot via matplotlib Antonio 4 8,347 Jun-19-2018, 05:57 PM
Last Post: Antonio

Forum Jump:

User Panel Messages

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