Matplotlib custom markers

I would like markers such as empty squares with +, or x, or., Or everything inside with adjustable thickness; In fact, those in Origin. It seems to be in need of customization.

Code example

:

import numpy as np import matplotlib.pyplot as plt plt.plot(np.arange(10) ** 2, 'k-', marker = 's', mfc = 'none', lw = 2, mew = 2, ms = 20) plt.show() 
+3
source share
2 answers

Using text , you can use any character available in your fonts. You need to scroll them yourself, but I don’t think you can constantly control their line width (although, of course, you can choose bold, etc., if any).

enter image description here

 from numpy import * import matplotlib.pyplot as plt symbols = [u'\u2B21', u'\u263A', u'\u29C6', u'\u2B14', u'\u2B1A', u'\u25A6', u'\u229E', u'\u22A0', u'\u22A1', u'\u20DF'] x = arange(10.) y = arange(10.) plt.figure() for i, symbol in enumerate(symbols): y2 = y + 4*i plt.plot(x, y2, 'g') for x0, y0 in zip(x, y2): plt.text(x0, y0, symbol, fontname='STIXGeneral', size=30, va='center', ha='center', clip_on=True) plt.show() 

You can also use plot directly, although rendering doesn't look so good, and you don't have much control over characters.

 plt.figure() for i, symbol in enumerate(symbols): y2 = y + 4*i plt.plot(x, y2, 'g') marker = "$%s$" % symbol plt.plot(x, y2, 'k', marker=marker, markersize=30) 

enter image description here

+6
source

Is this what you want?

Custom markers by overplotting

I did this by flipping this way:

 import numpy as np import matplotlib.pyplot as plt plt.plot(np.arange(10) ** 2, 'k-', marker = 's', mfc = 'none', lw = 2, mew = 2, ms = 20) plt.plot(np.arange(10) ** 2 + 20, 'k-', marker = '+', mfc = 'none', lw = 2, mew = 2, ms = 20) plt.plot(np.arange(10) ** 2 + 20, 'k-', marker = 's', mfc = 'none', lw = 2, mew = 2, ms = 20) plt.show() 
+3
source

Source: https://habr.com/ru/post/1483830/


All Articles