python – 我需要一个数字吗?它们适用于什么?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 我需要一个数字吗?它们适用于什么?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1602字,纯文字阅读大概需要3分钟。
内容图文
![python – 我需要一个数字吗?它们适用于什么?](/upload/InfoBanner/zyjiaocheng/728/f4b75a308f4044a494253ff4987bced6.jpg)
我已经开始使用matplotlib,我有点困惑为什么数字存在.有时我会看到声明图形的代码,然后绘制一个图表,有时我看到这样的事情:
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('initial.dat','float')
plt.plot(data[:,0], data[:,1])
plt.xlabel("x (Angstroms)")
plt.ylabel("V (eV)")
plt.savefig('v.png',bbox_inches='tight')
plt.clf()
我阅读了关于图和情节的文档,但我没有得到它.为什么数字存在?
解决方法:
使用matplotlib创建一些绘图后,图形将始终存在.
introductory matplotlib page可能会有所帮助:
07001
The whole figure. The figure keeps track of all the child Axes, a smattering of ‘special’ artists (titles, figure legends, etc), and the canvas. (Don’t worry too much about the canvas, it is crucial as it is the object that actually does the drawing to get you your plot, but as the user it is more-or-less invisible to you). A figure can have any number of Axes, but to be useful should have at least one.
你可以想象这个数字是你绘制情节的白纸.一个数字有一些大小,也许是一个背景,最重要的是它是你绘制的所有东西的容器.在大多数情况下,这将是一个或多个轴.如果没有任何数字,就不会有任何纸张来绘制你的情节(你不能在空中划线).
即使您没有明确地创建该图,它也会在后台自动创建.
import matplotlib.pyplot as plt
plt.plot([1,2,3])
# at this point we already have a figure, because the plot needs to live somewhere
# we can get a handle to the figure via
figure = plt.gcf()
当你明确需要一个数字时的例子:
>如果你想创建第二个数字.
plt.plot([1,2,3])
plt.figure(2)
plt.plot([2,4,6])
>如果要设置图形尺寸或其他图形参数.
plt.figure(figsize=(5,4), dpi=72)
>如果要更改子图的填充.
fig, ax=plt.subplots()
fig.subplots_adjust(bottom=0.2)
内容总结
以上是互联网集市为您收集整理的python – 我需要一个数字吗?它们适用于什么?全部内容,希望文章能够帮你解决python – 我需要一个数字吗?它们适用于什么?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。