在matplotlib中绘制极小的值 [英] Plot extremely small values in matplotlib
问题描述
我正在尝试在Jupiter Notebook(在Macbook Pro上)中使用matplotlib绘制一些极小的值.但是,无论我是否设置了 y 轴限制,我得到的只是一条平线.我所追求的是关于y轴表示法的示例(png).这是我的代码:
I am trying to plot some extremely small values with matplotlib in jupiter notebook (on a macbook pro). However, regardless if I set the y-axis limits, all I get is a flat line. What I am after is something like the example (png) below with regard to y-axis notation. Here's my code:
%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(13,6))
ax = fig.add_subplot(111)
plt.hold(True)
ax.plot([0.2, 0.5, 0.8], [4E-300, 5E-300, 4E-300], marker='.')
这是我追求的有关y轴值和符号的示例:
And here's an example of what I am after with regard to y-axis values and notation:
即使使用以下代码:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(13,6))
ax = fig.add_subplot(111)
plt.hold(True)
xs = np.linspace(0, 1, 101)
ys = 1e-300 * np.exp(-(xs-0.5)**2/0.01)
ax.plot(xs, ys, marker='.')
我得到以下情节:
推荐答案
Matplotlib(不像 Mathematica)希望您为图中所有感兴趣的点提供 x 和 y 值.您可以更改代码以在单位间隔中均匀间隔均匀地评估某些函数(例如高斯)
Matplotlib (unlike, say Mathematica) expects you to supply the x- and y- values for all the points of interest in the plot. You could alter you code to evenly evaluate some function (say a gaussian) at even spacing in the unit interval
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(13,6))
ax = fig.add_subplot(111)
plt.hold(True)
xs = np.linspace(0, 1, 101)
ys = 1e-300 * np.exp(-(xs-0.5)**2/0.01)
ax.plot(xs, ys, marker='.')
哪个给:
这篇关于在matplotlib中绘制极小的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!