1

We can customize markers according to

import matplotlib as mpl
mpl.rcParams['text.usetex'] = True # enable latex support
mpl.style.use('fivethirtyeight')   # gray background

import matplotlib.pyplot as plt

plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="$abc$",
    markersize=30
)

which gives

enter image description here

How do we make the line skip the region behind each custom marker?

(Without manually adding/subtracting from the individual points)

Stefan
  • 1,697
  • 15
  • 31

1 Answers1

2

You can use a second marker with a white filling.

import matplotlib.pyplot as plt

plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="o",
    markersize=30,
    markerfacecolor = 'white',
    markeredgecolor = 'white',
    color = 'blue'
)
plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="$abc$",
    markersize=30,
    linestyle = 'none',
    color = 'blue'
)

enter image description here

Edit: But this does not work with a custom background. To achieve that, you can adjust the markeredgewidth to be a little larger than your custom markers.

import seaborn as sns
sns.set()
plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="$abc$",
    markersize=30,
    markeredgewidth=6,
    mec='white',
    color = 'blue'
)
plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="$abc$",
    markersize=30,
    linestyle = 'none',
    color = 'blue'
)

enter image description here

Similar question Custom plot linestyle in matplotlib

PythonF
  • 456
  • 1
  • 5
  • 21
  • 1
    The custom background issue you mentioned can be fixed by setting the circle color not to `white`, but to the figure facecolor `plt.rcParams['figure.facecolor']`. – Stefan Feb 06 '21 at 12:49