matplotlib PatchCollection绘制了一个超大的箭头补丁

时间:2017-11-21 08:35:23

标签: python matplotlib

让我们使用FancyArrowPatch在两个散点之间绘制一个箭头:

import matplotlib.pyplot as plt
import matplotlib as mpl

fig, ax  = plt.subplots()

points = ax.scatter([0,1],[0,1], marker='o', s=300)
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutation_scale=20)
ax.add_patch(arrow)

fig.show()

看起来不错

enter image description here

现在,让我们使用PatchCollection进行相同的绘图

import matplotlib.pyplot as plt
import matplotlib as mpl

fig, ax  = plt.subplots()

points = ax.scatter([0,1],[0,1], marker='o', s=300)
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutation_scale=20)
col = mpl.collections.PatchCollection([arrow])
ax.add_collection(col)
fig.show()

有人可以澄清发生了什么吗? enter image description here

1 个答案:

答案 0 :(得分:1)

<Window x:Class="NI.TestStand.WPFControls.Views.DisplayBannerView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:NI.TestStand.WPFControls" mc:Ignorable="d" Title="DisplayBanner" x:Name="DisplayBannerMessage" Height="500" Width="800" MinHeight="300" MinWidth="500"> <Window.Resources> <Style x:Name="BaseWindowFont" TargetType="Window"> <Setter Property="FontFamily" Value="Arial"></Setter> <Setter Property="FontSize" Value="16"></Setter> </Style> </Window.Resources> <Grid> <Border BorderBrush="Black" BorderThickness="2"> <DockPanel LastChildFill="True"> <Button x:Name="butOK" DockPanel.Dock="Bottom" Margin="10" Content="OK" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="10" Width="150" Click="butOK_Click"/> <Label x:Name="main_message" Padding="15" FontSize="50" Content="MAIN_MSG" DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalContentAlignment="Center" /> <Border BorderBrush="Chocolate" BorderThickness="2" Margin="10" Name="messages_border"> <ListBox Background="{Binding ElementName=DisplayBannerMessage, Path=Background}" Foreground="Black" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" VerticalContentAlignment="Top" VerticalAlignment="Stretch" x:Name="detail_message"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}" ToolTip="{Binding}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Border> </DockPanel> </Border> </Grid> </Window> 主要设计用于注释。显然缺乏与其他补丁的兼容性,因此也存在PatchCollection。 (正如@tom在评论中指出的那样,链接到[本期])。

解决方法可能是从箭头的路径创建新补丁并将新补丁添加到集合中。这不允许保留FancyArrowPatch的所有功能,因此最终是否可以使用PatchCollection是不是更好的解决方案。

FancyArrowPatch