Код: Выделить всё
import numpy as np
import matplotlib.pyplot as plt
import itertools
r = -10
q = 10
a = -5
b = 5
def plot_power_functions(n_list, x_min=a, x_max=b):
# Create an array of x values
x = np.linspace(x_min, x_max, 400)
# Cyclical color generator
colors = itertools.cycle(plt.cm.Set1.colors) # Colors from the Set1 colormap
# Create the plot
plt.figure(figsize=(10, 6))
# Plot each function
for n in n_list:
y = x ** n
color = next(colors) # Get the next color from the cycle
# Create a proper label
label = f'f(x) = x^{n}'
# Plot the function
plt.plot(x, y, label=label, color=color)
# Add labels and title
plt.axhline(0, color='black', linewidth=1) # x-axis
plt.axvline(0, color='black', linewidth=1) # y-axis
# Add arrows at the end of the axes
plt.annotate('', xy=(x_max, 0), xytext=(x_min, 0),
arrowprops=dict(facecolor='black', width=0.5, headwidth=6)) # Arrow on the x-axis
plt.annotate('', xy=(0, q), xytext=(0, 0),
arrowprops=dict(facecolor='black', width=0.5, headwidth=6)) # Arrow on the y-axis
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('Plot of power functions f(x) = x^n')
# Set axis limits
plt.xlim(x_min, x_max)
plt.ylim(r, q) # y-axis limits, adjustable based on the functions
# Show the legend
plt.legend()
# Show the plot
plt.grid(True)
plt.show()
# Example usage:
n_list = [-2, -4]
plot_power_functions(n_list)
- График сохранялся как результат.
- После сохранения , я хочу выполнить некоторые преобразования сохраненного изображения, например:
- Зеркальное отображение графика по оси Y.
- Поворот изображения поверните график на 90 градусов по часовой стрелке.
Может ли кто-нибудь помочь мне со следующим?
- Сохранение графика в виде изображения внутри самой функции.
- Применение преобразований (отражение оси Y и поворот на 90 градусов по часовой стрелке) вращение) к сохраненному изображению графика.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ring-and-r