Draw axis lines or the origin for Matplotlib contour plot

75,000

Solution 1

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

Solution 2

Can't you just overlay a straight line?

plt.plot([0,0],[-4,4],lw=3,'w')
Share:
75,000
nos
Author by

nos

Hello fellow programmers! I maintain open source software and blog about science and technology in my spare time. Main projects: gita: A command-line tool to manage multiple git repos (1000+ ⭐) blog where I write about math, physics, coding, and hobbies youtube channel: productivity hacks and coding tips

Updated on September 13, 2020

Comments

  • nos
    nos over 3 years

    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