VSCode Jupyter – Plots displaying differently in different files despite using same backend
Question:
I am trying to plot some data using the VSCode Jupyter Notebook editor. Not sure if that’s relevant.
Here is the code for generating my plot:
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
G = 32.2 # [ft/s^2]
v_0 = 8 # [ft/s]
theta = 45 # [deg]
theta_rad = theta * np.pi/180
x_0 = 0 # [ft]
v_0x = v_0 * np.cos(theta_rad) # [ft/s]
a_x = 0 # [ft/s^2]
y_0 = 3 # [ft]
v_0y = v_0 * np.sin(theta_rad) # [ft/s]
a_y = -G # [ft/s^2]
t_final = (v_0y + np.sqrt(v_0y**2 + 2*G*y_0)) / G
N = 50
t = np.linspace(0, t_final, N)
x = x_0 + v_0x*t + 1/2 * a_x * t**2
y = y_0 + v_0y*t + 1/2 * a_y * t**2
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
ax.set_aspect('equal')
plt.grid()
plt.show()
Trying this code in the first .ipynb
file results in this plot:
Trying this code in a different .ipynb
file results in this plot:
When running matplotlib.get_backend()
both files return 'module://matplotlib_inline.backend_inline'
.
This behavior persists after restarting VSCode and my PC, and seems to depend on the file somehow.
Why is this happening? How can I force VSCode/Jupyter to use the style in the second plot?
Answers:
The issue is the library I was importing was calling sns.set()
internally
I am trying to plot some data using the VSCode Jupyter Notebook editor. Not sure if that’s relevant.
Here is the code for generating my plot:
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
G = 32.2 # [ft/s^2]
v_0 = 8 # [ft/s]
theta = 45 # [deg]
theta_rad = theta * np.pi/180
x_0 = 0 # [ft]
v_0x = v_0 * np.cos(theta_rad) # [ft/s]
a_x = 0 # [ft/s^2]
y_0 = 3 # [ft]
v_0y = v_0 * np.sin(theta_rad) # [ft/s]
a_y = -G # [ft/s^2]
t_final = (v_0y + np.sqrt(v_0y**2 + 2*G*y_0)) / G
N = 50
t = np.linspace(0, t_final, N)
x = x_0 + v_0x*t + 1/2 * a_x * t**2
y = y_0 + v_0y*t + 1/2 * a_y * t**2
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
ax.set_aspect('equal')
plt.grid()
plt.show()
Trying this code in the first .ipynb
file results in this plot:
Trying this code in a different .ipynb
file results in this plot:
When running matplotlib.get_backend()
both files return 'module://matplotlib_inline.backend_inline'
.
This behavior persists after restarting VSCode and my PC, and seems to depend on the file somehow.
Why is this happening? How can I force VSCode/Jupyter to use the style in the second plot?
The issue is the library I was importing was calling sns.set()
internally