Я пытаюсь создать график, в котором график выводит правильную шкалу, измеренную по меткам, а не общий размер фигуры (который включает в себя такие вещи, как поле вокруг графика). < /p>
Как настроить график, как точное, как измерено по клещам? Предпочтительно, я бы хотел, чтобы один тик был один дюйм. < /P>
ниже мой код: < /p>
import numpy as np
import matplotlib.pyplot as plt
# Define the function you want to plot
**def my_function(x):
return np.sin(x)+5
**# Define the number of inches per unit
**scale_factor = 1.0 # 1 unit = 1 inch
# Set figure size based on the scale (Ensure ticks match real inches)
x_range = 8 # How many units on the x-axis
y_range = 12 # How many units on the y-axis
fig_width = x_range * scale_factor # Scale width to inches
fig_height = y_range * scale_factor # Scale height to inches
dpi = 2400 # High DPI for accurate scaling
# Generate data
x = np.linspace(0, 2*np.pi, 10000)
y = my_function(x)
# Create the figure with correct physical dimensions
fig, ax = plt.subplots(figsize=(fig_width, fig_height), dpi=dpi)
ax.fill_between(x, y, 0, label="y = sin(x)+5", color='blue')
# Set tick intervals to match real inches
ax.set_xticks(np.arange(0, x_range + 1, 1)) # 1-inch spaced ticks
ax.set_yticks(np.arange(0, y_range+1, 1)) # Adjust as needed
# Set the major ticks to be 1 inch apart
ax.xaxis.set_major_locator(plt.MultipleLocator(1))
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
# Save the figure
plt.savefig("scaled_tick_plot.svg", dpi=dpi, bbox_inches='tight')
# Show the plot
plt.show()
< /code>
Я получаю что -то близкое, но кажется, что оси x и y масштабируются немного по -разному. Есть ли обходные пути к этому? Я хотел бы, чтобы они были точно такими же.>
Подробнее здесь: https://stackoverflow.com/questions/795 ... sely-1-inc
Как я могу масштабировать сюжет в Matplotlib так, чтобы отметки клещей были точно 1 дюйм? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Чтение CSV со столбцом отметки времени эпохи в качестве отметки времени.
Anonymous » » в форуме Python - 0 Ответы
- 39 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Чтение CSV со столбцом отметки времени эпохи в качестве отметки времени.
Anonymous » » в форуме Python - 0 Ответы
- 27 Просмотры
-
Последнее сообщение Anonymous
-