I'm trying to create some extra vertical whitespace in a legend produced using matplotlib.pyplot
. However, want this extra whitespace to only be between two entries in the legend, while the remaining entries are left untouched. I have a MWE and the image it produces, edited to show where I want the extra whitespace.
import matplotlib.pyplot as plt
plt.plot([0,1],[.2,.2],label = "A")
plt.plot([0,1],[.4,.4],label = "B")
plt.plot([0,1],[.6,.6],label = "C")
plt.plot([0,1],[.8,.8],label = "D")
plt.legend(loc='upper right',labelspacing=.3)
plt.ylim(0,1)
plt.show()
You probably have to use a Proxy Artist for this. Here is an example:
a, = plt.plot([0,1],[.2,.2],label = "A")
b, = plt.plot([0,1],[.4,.4],label = "B")
c, = plt.plot([0,1],[.6,.6],label = "C")
d, = plt.plot([0,1],[.8,.8],label = "D")
plt.legend([a,b,c,matplotlib.lines.Line2D([],[],linestyle=''),d],['A','B','C','','D'], loc='upper right',labelspacing=.3)
plt.ylim(0,1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With