绘制轴线或Matplotlib等高线图的原点 [英] Draw axis lines or the origin for Matplotlib contour plot
本文介绍了绘制轴线或Matplotlib等高线图的原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的轮廓图中使用白色绘制 x = 0
和 y = 0
轴。如果那太麻烦了,我想用一个白点表示原点在哪里。
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()
推荐答案
有很多选项(例如居中的棘齿 ),但就您而言,使用 轴线
和 axvline
。
There are a number of options (E.g. centered spines), but in your case, it's probably simplest to just use axhline
and axvline
.
例如
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()
这篇关于绘制轴线或Matplotlib等高线图的原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文