Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw axis lines or the origin for Matplotlib contour plot

I want to draw x=0 and y=0 axis in my contour plot, using a white color. If that is too cumbersome, I would like to have a white dot denoting where the origin is.

My contour plot looks as follows and the code to create it is given below.

xvec = linspace(-5.,5.,100)                                X,Y = meshgrid(xvec, xvec)                                 fig = plt.figure(figsize=(6, 4))                       contourf(X, Y, W,100)                              plt.colorbar()                                     

enter image description here

like image 707
nos Avatar asked Mar 07 '12 21:03

nos


People also ask

How do I change the origin in matplotlib?

To put the origin at the center of the figure we use the spines module from the matplotlib module. Basically, spines are the lines connecting the axis tick marks and noting the boundaries of the data area.


1 Answers

There are a number of options (E.g. centered spines), but in your case, it's probably simplest to just use axhline and axvline.

E.g.

import numpy as np import matplotlib.pyplot as plt  xvec = np.linspace(-5.,5.,100)                                x,y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y)                                  plt.contourf(x, y, z, 100)                              plt.colorbar()   plt.axhline(0, color='white') plt.axvline(0, color='white')  plt.show() 

enter image description here

like image 123
Joe Kington Avatar answered Sep 19 '22 21:09

Joe Kington