···
On Fri, Jan 4, 2013 at 1:22 PM, gsal <salgerman@…287…> wrote:
can you provide an example? The reference help is only two lines!
Given:
> import numpy as np
>
> import matplotlib.pyplot as plt
>
>
>
> fig = plt.figure()
>
> ax = fig.add_subplot(111)
>
> ax.broken_barh([ (110, 30), (150, 10) ] , (10, 9), facecolors='b',
>
> label='barh')
>
>
>
> ax.set_xlim((0,200))
>
> ax.set_ylim((0,50))
>
>
>
> ax.legend()
>
>
>
> plt.show()
>
How do I import what in order to, say, create a plot
“plot([0.0],[0.0],‘bs’)” so that I can at least plot a marker of the same
color as my broken_barh so that when the legend is added, the correct icon
precedes the label?
I tried adding
pp = plt.plot([80],[40],‘bs’, label=‘proxy artist’)
to the previous program, right before the legend command, but it actually
plots the marker, too.
Is there a way to import “plot” or “Line2D” or something so that I can
produce an artist that is NOT related to the plot and, hence, not plotted?
(is that what “proxy artist” means?).
Yes. Proxy artists are created in memory but never added to the axes object. Here’s an expanded version of the example:
import matplotlib.patches as mpatch
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
patch = mpatch.Rectangle((0, 0), 1, 1, fc=“r”)
ax.legend([patch], [“Proxy artist”])
plt.show()
So for your example, I’d do the following:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatch
fig = plt.figure()
ax = fig.add_subplot(111)
ax.broken_barh([ (110, 30), (150, 10) ] , (10, 9), facecolors=‘b’, label=‘barh’)
ax.set_xlim((0,200))
ax.set_ylim((0,50))
fakeredbar = mpatch.Rectangle((0, 0), 1, 1, fc=“r”)
fakebluebar = mpatch.Rectangle((0, 0), 1, 1, fc=“b”)
ax.legend([fakeredbar, fakebluebar], [‘Red Data’, ‘Blue Data’])
plt.show()
Now to me, it seems very strange that broken_barh doesn’t generate any items in a legend. Not sure why that is but it seems like a bug.
Hope that helps,
-paul