epfl-lts2 / pygsp

Graph Signal Processing in Python
https://pygsp.rtfd.io
BSD 3-Clause "New" or "Revised" License
483 stars 93 forks source link

Possibility to change node shape when plotting signal? #85

Closed StefanBloemheuvel closed 4 years ago

StefanBloemheuvel commented 4 years ago

Hi pygsp team,

I was trying to find a way to change the shape of a node, is that possible? I cannot seem to find the functionality to do so. I did find the way to change vertex size and color, but not the shape of the nodes. I have two types of sensors in my network and I would like to show that clearly in my figures.

Kind regards and thanks in advance!

Stefan

mdeff commented 4 years ago

The PyGSP uses matplotlib for plotting. Hence you can do any customization with matplotlib directly.

For example:

from matplotlib import pyplot as plt
import pygsp as pg
graph = pg.graphs.Sensor()
fig, ax = plt.subplots()
graph.plot(ax=ax)
del ax.collections[1]
ax.scatter(*graph.coords.T, marker='s')

example

Depending on the amount of customization required, it might be easiest to plot the graph with matplotlib. After all, it's just a scatter with a set of lines.

StefanBloemheuvel commented 4 years ago

Hi @mdeff , thanks for your response. There is only one issue, since this procedure removes the signal colours from the plot. How could this procedure take place while still showing a signal plotted on the graph?

mdeff commented 4 years ago

ax.scatter(*graph.coords.T, c=mysignal, marker='s')

You can do anything matplotlib can (e.g., changing marker size, colormaps, etc.). See matplotlib's doc.