无法在木星笔记本中将matplotlib图形保存为jpeg(空白)

时间:2020-01-23 20:14:15

标签: python matplotlib plot save figure

我无法将身材保存到jpeg(或其他任何文件)(空白)

x=list(df2['DAYTIME'])
z=list(df2['av100002 - temp Wywiew'])
x3= x[::75]


fig1 = plt.figure()
axes1 = fig1.add_axes([0,30,3.5,1.4])
axes1.set_title('Nawiew')


axes1.plot(x,z, lw=3)

axes1.set_xticks(x3)  

plt.xticks(x3, rotation=60)
fig1.savefig('xx.png', dpi=200)

2 个答案:

答案 0 :(得分:0)

轴的位置不正确,使轴偏离了图形。

尝试axes1 = fig1.add_subplot()进行快速修复,creates an axes centered in the figure space

如果要使用add_axes()手动放置轴,请使用the coordinates are given in figure fractions。坐标为[left,bottom,width,height],其中0表示图形的左/下边缘,1表示图形的右/上边缘。

默认情况下,fig.add_subplot()等效于fig.add_axes([0.125, 0.11, 0.9, 0.88])

完整代码:

import matplotlib.pyplot as plt

fig1 = plt.figure()
axes1 = fig1.add_subplot(111)
axes1.set_title('Nawiew')
fig1.savefig('xx.png', dpi=200)

enter image description here

答案 1 :(得分:-1)

好吧,我知道了

` fig,axes = plt.subplots(rows = 1,ncols = 1,figsize =(30,3.5))

colnames(df) <- c(paste0("SCCOUNTRY", 2:7))

library(data.table)

melt(setDT(df), id.vars = "ID", measure = patterns("^SCCOUNTRY"))[nchar(value) > 0 & complete.cases(value)] -> foo
unique(foo, by = c("ID", "value")) -> foo2
crossprod(table(foo2[, c(1,3)])) -> mymat
diag(mymat) <- ifelse(diag(mymat) <= 1, 0, mymat)

` 谢谢您的帮助