Description
Issue (?)
When plotting a arrow (with FancyArrowPatch
from matplotlib.patches
), and exporting it to a picture, the size of its head is not consistent with what is displayed in the interactive figure. (The linewidth seems to remain OK between interactive and exported file, whatever format is used.)
As far as I understand, it seems to be DPI-related:
- If the DPI value is the same between the interactive figure and the export made with
savefig
, then everything is fine. - However, if I want to export with DPI 3 times bigger than in the interactive figure (for example 300 DPI instead of 100 DPI), one workaround I found is to use a mutation_scale 3 times bigger than before when plotting the interactive figure. Unfortunately, it is neither really convenient nor satisfying as it affects what is displayed in the interactive figure (the arrow head is 3 times bigger...)
I don't know if it is a bug or the expected behavior, but I find it disturbing to have an export that is (that) different from the interactive display.
Environment infos
- Linux, Python 2.7 (from Anaconda2), Matplotlib v1.5.0
- Interactive backend is Qt4Agg
Example script
Here is a script that generates a figure with 2 arrows (FancyArrowPatch), and exports it to different formats:
import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch
plt.ion() # My interactive backend is Qt4Agg, with default @ 80 DPI
""" Prepare and plot 2 FancyArrowPatch instances, the 2nd one with a
mutation_scale parameter 3 times bigger than the 1st one.
"""
common_opts = dict(arrowstyle=u'->', lw=3)
arrow_patch_0 = FancyArrowPatch(posA=(0.2, 0.8), posB=(0.8, 0.65),
mutation_scale=50, **common_opts)
arrow_patch_1 = FancyArrowPatch(posA=(0.2, 0.2), posB=(0.8, 0.45),
mutation_scale=150, **common_opts)
fig, ax = plt.subplots(figsize=(8, 6), dpi=100)
ax.text(0.2, 0.85, "mutation_scale = 50", ha='left', va='bottom')
ax.text(0.2, 0.15, "mutation_scale = 150", ha='left', va='top')
for arrow_patch in [arrow_patch_0, arrow_patch_1]:
ax.add_patch(arrow_patch)
""" Export to different formats, with different DPI values if rasterized.
"""
common_prefix = 'FancyArrowPatch_testfile'
fig.savefig(common_prefix + '.eps')
fig.savefig(common_prefix + '.pdf')
fig.savefig(common_prefix + '_300dpi.png', dpi=300)
fig.savefig(common_prefix + '_100dpi.png', dpi=100)
fig.savefig(common_prefix + '_300dpi.jpg', dpi=300)
fig.savefig(common_prefix + '_100dpi.jpg', dpi=100)``
And below is a picture that compares the 6 different output files (2 x 3 bottom panels) with a screenshot of the interactive figure (top center panel).
Observations about the example
One can see that with the raster formats (PNG and JPG):
- @ 100 DPI (blue labels), the exports are the same as in the screenshot of the interactive display with 100 DPI.
- @ 300 DPI (red labels), the exports differ from the interactive display. Besides, the arrow head with mutation_scale = 150 seems to be as big as the arrow head with mutation_scale = 50 @ 100 DPI.
Concerning the (at least partially) vector formats that I tested (PDF and EPS, with purple labels), one can observe that the arrow heads do not have exactly the same size as in the interactive display either (they are slightly bigger).