Last active
November 15, 2023 19:45
-
-
Save pozitron57/b150919286aecce280b0d38dc50702d4 to your computer and use it in GitHub Desktop.
F_friction(t) plot for phys.pro/problems/237/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import rc, rcParams | |
from matplotlib.ticker import FuncFormatter | |
from matplotlib.ticker import MultipleLocator | |
# Plot setup {{{ | |
lw = 2 | |
k=1.4 | |
rcParams['font.size'] = 23 | |
rcParams['text.usetex'] = True | |
rcParams['font.sans-serif'] = ['Computer Modern'] | |
rc('text.latex', preamble=r'\usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{bm}') | |
rc('axes', linewidth=lw) | |
rc('xtick.major', size=4, width=lw) | |
rc('ytick.major', size=4, width=lw) | |
fig, ax = plt.subplots(figsize=(12,7)) | |
fig.subplots_adjust(left=.20, bottom=.13, right=.90, top=.68) | |
# Set comma as a decimal separator (bad) | |
import locale | |
locale.setlocale(locale.LC_NUMERIC, 'ru_RU') | |
rcParams['axes.formatter.use_locale'] = True | |
def format_decimal(value, tick_number): | |
value = round(value, 2) # Fixes 0,60000000000001 instead of 0,6 | |
return '$' + str(value).replace('.', '{,}') + '$' | |
#ax.yaxis.set_major_formatter(FuncFormatter(format_decimal)) | |
#ax.xaxis.set_major_formatter(FuncFormatter(format_decimal)) | |
#}}} | |
# Set parameters | |
m = 2 # kg | |
R = 1 # m | |
g = 10 # m/s² | |
a = np.radians(30) # deg | |
T = 5 # s | |
w = 2*np.pi / T # rad/s | |
t = np.linspace(0, 2*T, 1000) | |
F = m*g* np.sqrt( (w**2*R/g)**2 + 2*w**2*R*np.sin(a)/g * np.cos(w*t) + np.sin(a)**2) | |
R_values = np.array([0.3*g*np.sin(a)/w**2, g*np.sin(a)/w**2, 2*g*np.sin(a)/w**2, 3*g*np.sin(a)/w**2]) | |
colormap = plt.cm.get_cmap('Blues') | |
normalize = plt.Normalize(R_values.min()-3.0, R_values.max()) | |
for R in R_values: | |
F = m * g * np.sqrt((w**2 * R/g)**2 + 2 * w**2 * R * np.sin(a)/g * np.cos(w*t) + np.sin(a)**2) | |
ax.plot(t, F, label=r'$m\omega^2R={}\cdot mg\sin\alpha$'.format(round(w**2*R/(g*np.sin(a)), 1)).replace('.', '{,}'), | |
lw=lw, color=colormap(normalize(R))) | |
print (R) | |
## Add colorbar | |
#sm = plt.cm.ScalarMappable(cmap=colormap, norm=plt.Normalize(R_values.min(), R_values.max())) | |
#sm.set_array([]) | |
#cbar = plt.colorbar(sm, label=r'$R$') | |
ax.set_xlabel(r'$t, \textrm{с}$') | |
ax.set_ylabel(r'$F_\textrm{тр},\;\textrm{Н}$', labelpad=13) | |
ax.grid() | |
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.6), | |
ncol=1, fancybox=False, shadow=False) | |
#ax.yaxis.set_major_locator(plt.MaxNLocator(5)) | |
#ax.xaxis.set_major_locator(plt.MaxNLocator(6)) | |
ax.set_ylim([0,42]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment