Я использую matplotlib для построения столбцов матрицы в виде отдельных прямоугольников, используя matplotlib.patches.Rectangle. Почему-то все «внутренние» линии шире «внешних»? Кто-нибудь знает, что здесь происходит? Связано ли это с проблемой на Github?
Вот MRE:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.patches as patches
# set seed
np.random.seed(42)
# define number of cols and rows
num_rows = 5
num_cols = 5
# define gap size between matrix columns
column_gap = 0.3
# define linewidth
linewidth = 5
# Determine the width and height of each square cell
cell_size = 1 # Set the side length for each square cell
# Initialize the matrix
matrix = np.random.rand(num_rows, num_cols)
# Create the plot
fig, ax = plt.subplots(figsize=(8,6))
# Create a seaborn color palette (RdYlBu) and reverse it
palette = sns.color_palette("RdYlBu", as_cmap=True).reversed()
# Plot each cell individually with column gaps
for i in range(num_rows):
for j in range(num_cols):
# Compute the color for the cell
color = palette(matrix[i, j])
if column_gap > 0:
edgecolor = 'black'
else:
edgecolor = None
# Add a rectangle patch with gaps only in the x-direction
rect = patches.Rectangle(
(j * (cell_size + column_gap), i * cell_size), # x position with gap applied to columns only
cell_size, # width of each cell
cell_size, # height of each cell
facecolor=color,
edgecolor=edgecolor,
linewidth=linewidth
)
ax.add_patch(rect)
if column_gap > 0:
# Remove the default grid lines and ticks
ax.spines[:].set_visible(False)
# Set axis limits to fit all cells
ax.set_xlim(0, num_cols * (cell_size + column_gap) - column_gap)
ax.set_ylim(0, num_rows * cell_size)
# Disable x and y ticks
ax.set_xticks([])
ax.set_yticks([])
fig.show()
Я использую matplotlib для построения столбцов матрицы в виде отдельных прямоугольников, используя matplotlib.patches.Rectangle. Почему-то все «внутренние» линии шире «внешних»? Кто-нибудь знает, что здесь происходит? Связано ли это с проблемой на Github? Вот MRE: [code]import numpy as np import matplotlib.pyplot as plt import seaborn as sns import matplotlib.patches as patches
# set seed np.random.seed(42)
# define number of cols and rows num_rows = 5 num_cols = 5
# define gap size between matrix columns column_gap = 0.3
# define linewidth linewidth = 5
# Determine the width and height of each square cell cell_size = 1 # Set the side length for each square cell
# Initialize the matrix matrix = np.random.rand(num_rows, num_cols)
# Create the plot fig, ax = plt.subplots(figsize=(8,6))
# Create a seaborn color palette (RdYlBu) and reverse it palette = sns.color_palette("RdYlBu", as_cmap=True).reversed()
# Plot each cell individually with column gaps for i in range(num_rows): for j in range(num_cols):
# Compute the color for the cell color = palette(matrix[i, j])
# Add a rectangle patch with gaps only in the x-direction rect = patches.Rectangle( (j * (cell_size + column_gap), i * cell_size), # x position with gap applied to columns only cell_size, # width of each cell cell_size, # height of each cell facecolor=color, edgecolor=edgecolor, linewidth=linewidth )
ax.add_patch(rect)
if column_gap > 0:
# Remove the default grid lines and ticks ax.spines[:].set_visible(False)
# Set axis limits to fit all cells ax.set_xlim(0, num_cols * (cell_size + column_gap) - column_gap) ax.set_ylim(0, num_rows * cell_size)
# Disable x and y ticks ax.set_xticks([]) ax.set_yticks([])
fig.show() [/code] что создает: [img]https://i.sstatic.net/jt3QtpEFm. png[/img]
Моя цель — создать изображение с прозрачным кругом и непрозрачным белым фоном. Как прозрачное круглое отверстие в белом листе.
Когда я попробовал это, круг не стал прозрачным:
import matplotlib.pyplot as plt
import matplotlib.patches as patches...
Я пишу кумулятивную функцию вероятности с нуля и хотел визуально показать, где находится доверительный интервал, но стрелка слишком короткая:
fig, ax = plt.subplots(1,1)
ax.plot(np.linspace(1,500,500),Cumulative_increasing, - ,color= black )...
Мне нужно нарисовать прямоугольники с небольшим ВНУТРЕННИМ отступом (например, 2 пикселя), чтобы они не соприкасались с непосредственно соседними прямоугольниками. Я бы хотел, чтобы заполнение оставалось постоянным после любого изменения размера...
Проблема:
Я пытаюсь включить код, который позволяет pandas (и openpyxl или любому рабочему методу, который вы можете предоставить) правильно вводить ГИПЕРССЫЛКИ в DataFrame.
Однако, несмотря на кажущиеся успешные попытки в решениях GitHub и...
Проблема:
Я пытаюсь включить код, который позволяет pandas (и openpyxl или любому рабочему методу, который вы можете предоставить) правильно вводить ГИПЕРССЫЛКИ в DataFrame.
Однако, несмотря на кажущиеся успешные попытки в решениях GitHub и...