保存交互式pyplot图形

2024-06-26 02:14:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经为我的一些同事制作了一些带有交互式检查按钮的PyPlot。检查按钮用于显示相同的值,但来自不同的传感器。我想将生成的绘图发送给我的同事,并使用功能检查按钮。但是,如果我将文件另存为JPG/PNG,则功能将丢失。有没有一种方法可以将一个带有功能检查按钮的交互式python图形发送给其他不是python用户并且不太懂编程的人

代码不是超级相关,但发布在下面:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons
### FIGURE 1 ###

fig, ax = plt.subplots()
l0, = ax.plot(df1[vel_avg1],df1[htc1],color = 'C0', marker = 'o', label = 'HTC-1')
l1, = ax.plot(df1[vel_avg2],df1[htc2],color = 'C0', marker = 'o',label = 'HTC-2')
l2, = ax.plot(x_th, y_th, color = 'r', marker = 'o', markersize=0,
              label = 'Theoretical heat transfer coefficient')

plt.subplots_adjust(left=0.2)
ax.set_xlabel('Off-gas velocity (m/s)', fontsize = SMALL_SIZE)
ax.set_ylabel('Heat transfer coefficient (W/m2K)', fontsize = SMALL_SIZE)
lines1 = [l0, l1, l2]

# Make checkbuttons with all plotted lines with correct visibility
rax = plt.axes([0.05, 0.4, 0.1, 0.15])
labels1 = [str(line.get_label()) for line in lines1]
visibility1 = [line.get_visible() for line in lines1]
check1 = CheckButtons(rax, ('HTC-1','HTC-2'), visibility1)

def func(label):
    index = labels1.index(label)
    lines1[index].set_visible(not lines1[index].get_visible())
    plt.draw()

check1.on_clicked(func)

plt.suptitle('From ' + start_date + ' to ' + end_date)
plt.savefig('fig1.png')
plt.show()

seaborn是否具有类似于此或任何其他库的功能


Tags: import功能indexplotaslinepltax