我试图在任一轴上绘制一个没有刻度线或数字的图形(我使用传统意义上的轴,而不是matplotlib命名法!).我遇到的一个问题是matplotlib通过减去值N来调整x(y)ticklabels,然后在轴的末尾添加N.
这可能是模糊的,但下面的简化示例突出了问题,'6.18'是N的违规值:
import matplotlib.pyplot as plt
import random
prefix = 6.18
rx = [prefix+(0.001*random.random()) for i in arange(100)]
ry = [prefix+(0.001*random.random()) for i in arange(100)]
plt.plot(rx,ry,'ko')
frame1 = plt.gca()
for xlabel_i in frame1.axes.get_xticklabels():
xlabel_i.set_visible(False)
xlabel_i.set_fontsize(0.0)
for xlabel_i in frame1.axes.get_yticklabels():
xlabel_i.set_fontsize(0.0)
xlabel_i.set_visible(False)
for tick in frame1.axes.get_xticklines():
tick.set_visible(False)
for tick in frame1.axes.get_yticklines():
tick.set_visible(False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我想知道的三件事是:
如何首先关闭这种行为(虽然在大多数情况下它是有用的,但并不总是!)我已经查看了matplotlib.axis.XAxis
,找不到任何合适的东西
怎么能让N消失(即X.set_visible(False)
)
还有更好的方法来完成上述任务吗?我的最终情节将是图中的4x4子图,如果这是相关的.
是否可以在matplotlib图中保存(到png)单个子图?让我说我有
import pyplot.matplotlib as plt
ax1 = plt.subplot(121)
ax2 = plt.subplot(122)
ax1.plot([1,2,3],[4,5,6])
ax2.plot([3,4,5],[7,8,9])
Run Code Online (Sandbox Code Playgroud)
是否可以将两个子图中的每一个保存到不同的文件中,或者至少将它们分别复制到新图中以保存它们?
我在RHEL 5上使用版本1.0.0的matplotlib.
谢谢,
罗伯特
我尝试使用matplotlib电影作家生成一部电影.如果我这样做,我总是在视频周围留下白色边缘.有谁知道如何删除该保证金?
来自http://matplotlib.org/examples/animation/moviewriter.html的调整后的示例
# This example uses a MovieWriter directly to grab individual frames and
# write them to a file. This avoids any event loop integration, but has
# the advantage of working with even the Agg backend. This is not recommended
# for use in an interactive setting.
# -*- noplot -*-
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as manimation
FFMpegWriter = manimation.writers['ffmpeg']
metadata = dict(title='Movie Test', artist='Matplotlib',
comment='Movie support!') …
Run Code Online (Sandbox Code Playgroud) 我需要在 tif 文件中分析被选为子矩阵的图像的一部分。我想要原始格式的图像,没有多余的装饰(缩放,轴,标签等)......我怎么能做到这一点?
这是我现在使用的代码:
submatrix = im[x_min:x_max, y_min:y_max]
plt.imshow(submatrix)
plt.savefig("subplot_%03i_%03i.tif" % (index, peak_number), format = "tif")
Run Code Online (Sandbox Code Playgroud) 我想从wav文件中获取一个频谱图,然后将其保存为png,但是我只需要图像的内容(而不是轴或其他任何东西)。我遇到了
Matplotlib绘制的这些问题:删除轴,图例和空白区域
scipy:没有框架,轴,仅内容的savefig
我也阅读了Matplotlib文档,但似乎无用,因此上述问题的答案已过时或我做错事是因为简单
plt.savefig('out.png', bbox_inches='tight', pad_inches=0)
不做我想实现的目标。最初,我尝试遵循此指南,但是代码崩溃了。然后,我尝试了这种方法,但是由于它已经过时,因此我对其进行了一些修改:
import matplotlib.pyplot as plt
from scipy.io import wavfile
import numpy as np
def graph_spectrogram(wav_file):
rate, data = wavfile.read(wav_file)
pxx, freqs, bins, im = plt.specgram(x=data, Fs=rate, noverlap=384, NFFT=512)
plt.axis('off')
plt.savefig('sp_xyz.png', bbox_inches='tight', dpi=300, frameon='false')
if __name__ == '__main__': # Main function
graph_spectrogram('...')
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
也许它不可见,但是内容周围有一个白色边框(从最大到最小):左,下,上,右。我想要相同的图像,但只包含内容,没有其他内容。我该如何实现?我使用python 3.6和Matplotlib 2.0.2。
我为此目的编写了一个函数:
matplotlib
图形,但不显示它numpy
数组对于类似于第 1-2 点或第 4 点的任务,有很多问题和答案;对我来说,自动化第 5 点也很重要。因此,我首先将 @joe-kington 的答案和 @matehat 的答案和评论中的部分结合起来,并进行了一些小的修改,我得到了:
def mk_cmapped_data(data, mpl_cmap_name):
# This is to define figure & ouptput dimensions from input
r, c = data.shape
dpi = 72
w = round(c/dpi, 2)
h = round(r/dpi, 2)
# This part modified from @matehat's SO answer:
# /sf/answers/575322121/
fig = plt.figure(frameon=False)
fig.set_size_inches((w, h))
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
plt.set_cmap(mpl_cmap_name)
ax.imshow(data, …
Run Code Online (Sandbox Code Playgroud) matplotlib ×6
python ×6
plot ×2
animation ×1
colors ×1
image ×1
numpy ×1
spectrogram ×1
tiff ×1
video ×1