Question about Why I need to restart kernel everytime

Hi~

I’m a beginner in programming world, and sorry for not reading enough posts and ask question directly. I often use jupyter lab and use simple functions to plot formal engineering diagram and that’s all.
My question is :
I usually import some library in the first row, import data in the second row and the plotting code in another row.
Whenever I modified the plotting code, I can’t just compile the plotting code and get the new plot. However, I need to restart kernel, and re-compile all the import codes and plotting codes and then can get new plot.
This issue drives me crazy, can someone help me with that? Please!!

it’d surely be helpful to see a code example which has the mentioned characteristics, cause restarting the kernel should not be necessary.

1 Like

Sure. Thanks for your feedback. I just post the code as follows

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
import scienceplots

filename1 =“xxxx.csv”
filename2 =“xxxxx.csv”
df1 = pd.read_csv(filename1,comment=“!”)
df2 = pd.read_csv(filename2,comment=“!”)

y = [-10, 30]
with plt.style.context([‘science’, ‘ieee’,‘no-latex’,‘grid’]):
fig, ax = plt.subplots()
x=df1.freq
y1=df1.Gmax
y2=df1.Gumx
y3=df2.Gmax
y4=df2.Gumx
ax.set_xlabel(‘Frequency(GHz)’, fontsize=12)
ax.set_ylabel(‘Gmax/U(dB)’, fontsize=12)
ax.plot(x, y1, ‘-’, color = ‘blue’ ,label=“A”,linewidth=1)
ax.plot(x, y2, ‘-’, color = ‘red’ ,label=“B”,linewidth=1)
ax.plot(x, y3, ‘–’, color = ‘blue’ ,label=“C”,linewidth=1)
ax.plot(x, y4, ‘–’, color = ‘red’ ,label=“D”,linewidth=1)
ax.set_xlim(10,1000)
ax.set_xscale(‘log’)
ax.set_ylim(-10,30)
ax.legend(loc=3, prop={‘size’: 6})
plt.xticks(fontsize=10)
plt.yticks(np.arange(min(y), max(y)+1, 10), fontsize=10)
fig.savefig(‘ABCD.png’,bbox_inches=‘tight’)

i cannot reproduce this. please use markdown to correctly format your code. might be a longshot but have you tried to use plt.show() in the end?

1 Like

Hi~

Well, adding plt.show() in the end solves my problem!!!
Thanks for your feedback.

3 Likes