75645

Mapping a plus symbol with matplotlib [closed]

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.

Recommend

  • Raphaeljs Substring Text attributes
  • matplotlib's colormap
  • multiple iron-collapse not working, expands only first
  • Issue clearing the Tkinter Canvas widget using also matplotlib
  • Dendrogram or Other Plot from Distance Matrix
  • R - Keep log of all plots
  • How to apply a partial derivative Gaussian kernel to an image with OpenCV?
  • Deploying pre-encrypted configuration files to a production environment
  • Each Radiobutton for each form or 1 Form for all radiobuttons?
  • What does a hyphen at end of a term mean
  • Use sed with regex and (
  • Retrieving specified columns from a list of csv files to create a data data frame in R
  • How to override value that appears in a dropdown in the rails_admin gem
  • Breeze - Deleted Items nav properties bug
  • Java: can you cast Class into a specific interface?
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • javaw.exe and eclipse startup problems
  • AES padding and writing the ciphertext to a disk file
  • How to add date and time under each post in guestbook in google app engine
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • Convert array of 8 bytes to signed long in C++
  • Matplotlib draw Spline from multiple points
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Comma separated Values
  • Python: how to group similar lists together in a list of lists?
  • SQL merge duplicate rows and join values that are different
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Understanding cpu registers
  • coudnt use logback because of log4j
  • need help with bizarre java.net.HttpURLConnection behavior
  • Busy indicator not showing up in wpf window [duplicate]
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?