- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试保存 matplotlib数字到内存流,与 SO 上的另一个示例完全相同:
import matplotlib.pyplot as plt
import io
plt.figure()
plt.plot([1, 2])
plt.title("test")
buf = io.BytesIO()
plt.savefig(buf, format = 'png')
plt.savefig("real.png", format = 'png')
buf.seek(0)
data = buf.read()
buf.close()
f = open('copy.png', 'w')
f.write(data)
f.close()
我发现 copy.png 的尺寸稍大,应用程序拒绝打开它。这是某种编码问题吗?
背景:
我正在尝试使用 python.net 通过 matplotlib 渲染图形并将它们传递给 C# 进行绘图。我想避免将图像写入磁盘。理想情况下,我想写入某种可以在 C# 中使用的字节数组。
最佳答案
尝试以二进制模式打开文件。
f = open('copy.png', 'wb')
来自文档:
Python on Windows makes a distinction between text and binary files; the end-of-line characters in text files are automatically altered slightly when data is read or written. This behind-the-scenes modification to file data is fine for ASCII text files, but it’ll corrupt binary data like that in JPEG or EXE files. Be very careful to use binary mode when reading and writing such files.
关于c# - Matplotlib savefig to BytesIO 是不是有点不对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577110/
我正在尝试保存一个在 IPython 内联中工作正常的图形,但没有将包含轴和标题的图形保存到磁盘。 我在 matplotlibrc 中默认使用 TKAgg 后端 任何想法这里可能会出现什么问题?我已经
我正在尝试保存由大表(10000+行,18列)制成的大树状图,我附带了这段代码 from matplotlib import pyplot as plt from scipy.cluster.hier
嘿,我试着保存我的情节,但它总是切断我的头衔。我认为这是因为 y=1.05(设置与标题的距离)。我无法修复它。有没有办法保存整个图? time=round(t[time_period],0) most
我正在尝试使用 forloop 为我拥有的每组数据生成图形,但是虽然 .show() 命令生成了正确的图形,但 .savefig() 不断将先前绘制的值添加到新图形中。在我的 forloop 中,这是
在用matplotlib画图时,如果图例比较大,画在图中就会挡着线条,这时可以用以下语句把图例画到图外面: ?
我已经使用 matplotlib 制作了一个图形,现在我正在尝试使用 matplotlib.pyplot.savefig 将其保存到文件中 import matplotlib.pyplot as pl
使用 LsqFit 使用绘图 function run() # Allocate data x_data = [ 15.2, 19.9, 2.2, 11.8, 12.1, 18.1,
我有一个循环,它遍历一组“程序”名称,创建一个绘图并将其放置在每个带有 xlsxwriter 的工作表上。为此,它暂时将绘图本地保存为“chart.png” plt.savefig('chart{}.
我在带有标题和轴标签的 QtAggFigureCanvas (PyQt4) 中嵌入了一个 matplotlib 图(示例如下所示)。 我实现了一个按钮将图形保存到 png 文件。该图是通过以下方式创建
问题 我似乎无法获得 savefig()实际保存没有透明图形背景的PNG文件。 这是阅读并尝试了之前发布、回答、诅咒的所有建议,并且还多次阅读了 API 文档。我已经阅读了所有内容,但仍然无法获得不透
我惊讶地发现,当我将 savefig 与 transparent=True 一起使用时,这删除了我可能设置的facecolor。 如何才能不丢失我手动设置的任何背景颜色(包括白色)? 比较 图形用户界
我已从两个不同的数据帧中各加载一列,并将它们绘制在折线图上。该图表在我的屏幕上弹出,但我的 plt.savefig 命令不起作用,因为没有保存文件。 import matplotlib.pyplot
我有一个大的 3d numpy 数组,我想将每个切片(2d 数组)写出到一个类似 imshow 的图形(即值的热图)。作为一个具体的例子,假设数组的形状是 3x3x3000,所以我想要 3000 张图
Drawing a huge graph with networkX and matplotlib 我实际上是在重新提出相关问题。我想我可以更好地解释这个问题。在大图上调用 mathplotlib.s
我有一个内部分布式计算库,我们一直使用它来处理并行计算作业。进程分区后,它们运行数据加载和计算步骤,然后以“保存”步骤结束。通常这涉及将数据写入数据库表。 但对于特定任务,我需要每个过程的输出是一个包
我想默认使用 transparent=True 保存我所有的图像,所以我可以输入: savefig(fname.png) 代替 savefig(fname.png, transparent=True)
我在 pyplot 中有一个非常简单的饼图。相关代码是这样的: labels = 'SLoC', 'Violation' sizes = [nrOfLines-totviols, totviols]
我想做一些数据列的可视化总结+统计。我想将两个或多个子图与描述性表格组合起来,并将图形保存在本地。但是,保存绘图时,表格的一部分会被裁剪。 当我执行以下操作时 import numpy as np i
我想同时以三种格式保存一个图形。所以我使用的代码是这样的 import numpy as np import matplotlib.pyplot as plt x=np.linspace(0,1) y
我正在使用 pyplot.subplot() 制作条形图,然后另存为图像。目前 savefig 正在保存一个空图像。我想我有点卡住了,因为我没有找到很多关于条形图和子图的示例。 代码如下: nums
我是一名优秀的程序员,十分优秀!