![Mapping a plus symbol with matplotlib [closed]](https://www.xszz.org/skin/wt/rpic/t24.jpg)
Question:
I want to use mapplotlib to graph a plus symbol that looks like this:
_
_| |_
|_ _|
|_|
I've been reading through the matplotlib docs but, frankly, I'm not even sure what to search to fix my problem. Effectively I want to have two points on the same X axis (I.E. a vertical line) but I can't seem to figure out how to do this. Ideally I'd like to do this with one set of plot points, though I understand if this isn't possible.
Please let me know if I can clarify my problem in any way.
Answer1:<ol><li>Draw your desired figure on to graph paper,</li> <li>write down the x,y values of the corners,</li> <li>put those values into a pair of lists, (one for x and one for y), in the same order,</li> <li>plot it.</li> </ol>
For example:
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> y =[10, 20, 20, 30, 30, 40, 40, 30, 30, 20, 20, 10, 10]
>>> x =[10, 10, 0, 0, 10, 10, 20, 20, 30, 30, 20, 20, 10]
>>> line, = ax.plot(x, y, 'go-')
>>> ax.grid()
>>> ax.axis('equal')
(0.0, 30.0, 10.0, 40.0)
>>> plt.show()
Produces:<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/jTNdy.png" data-original="https://i.stack.imgur.com/jTNdy.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
Answer2:If you would have done a little search you should have found a few links how to create custom markers. The best I came up with to answer your question is to use a <a href="http://matplotlib.org/api/path_api.html" rel="nofollow">Path</a> object as marker. Therefore you can create a function which creates the desired path (I was to lazy to write the cross so I took a simpler rectangle):
def getCustomMarker():
verts = [(-1, -1), # left, bottom
(-1, 1), # left, top
(1, 1), # right, top
(1, -1), # right, bottom
(-1, -1)] # ignored
codes = [matplotlib.path.Path.MOVETO,
matplotlib.path.Path.LINETO,
matplotlib.path.Path.LINETO,
matplotlib.path.Path.LINETO,
matplotlib.path.Path.CLOSEPOLY]
path = matplotlib.path.Path(verts, codes)
return path
You are now able to plot any data with the desired custom marker:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
figure = plt.figure()
axes = figure.add_subplot(1, 1, 1)
axes.plot(x, y, marker=getCustomMarker(), markerfacecolor='none', markersize=3)
plt.show()
This enables you to plot any marker at any position you want it to be at the desired size.