简体   繁体   English

在jupyter中使用matplotlib绘制非常小的值

[英]Plot very small values with matplotlib in jupyter

I am trying to plot some extremely small values with matplotlib in jupyter notebook (on a macbook pro). 我试图在jupyter笔记本(在macbook pro上)中使用matplotlib绘制一些极小的值。 However, regardless if I set the y-axis limits, all I get is a flat line. 但是,无论是否设置y轴限制,我得到的都是一条平线。 What I am after is something like the example (png) below with regard to y-axis notation. 我所追求的是类似于以下有关y轴符号的示例(png)。 I also tried the same example outside of jupyter and I still get the same results. 我还在jupyter之外尝试了相同的示例,但仍然得到相同的结果。 Here's the code suggested by Andrew Walker on my previous question : 这是安德鲁·沃克(Andrew Walker)我之前的问题中 建议的代码:

%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='.')

Here's what I get: 这是我得到的:

在此处输入图片说明

And here's what I'm after: 这就是我的追求:

在此处输入图片说明

The easiest thing to do is to just plot your values multiplied by 10^300, and then change the y-axis label: 最简单的方法是将您的值乘以10 ^ 300,然后更改y轴标签:

%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 = np.exp(-(xs-0.5)**2/0.01)

ax.plot(xs, ys, marker='.')

ax.set_ylabel(r'Value [x 10^{-300}]')

You can use the set_ylim method on your axes object to do what you need, simply change your code to this and it would do what you need: 您可以在轴对象上使用set_ylim方法来完成所需的工作,只需将代码更改为此即可完成所需的工作:

%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.set_ylim([0,10^-299])

ax.plot(xs, ys, marker='.')

you may like to check This link for more info on this subject. 您可能需要检查此链接以获取有关此主题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM