Title only shows if called before nx.draw

1,953 views
Skip to first unread message

Alejandro

unread,
Aug 14, 2012, 12:42:46 PM8/14/12
to networkx...@googlegroups.com
Hi:

I found that a plot title (as in plt.title('A title')) only shows in the figure if it is call before calling nx.draw(G).

The following code illustrates this:

#############################
import networkx as nx
import matplotlib.pyplot as plt

G = nx.cycle_graph(5)

plt.figure()
nx.draw(G)
plt.title('A title')

plt.figure()
plt.title('A title')
nx.draw(G)

plt.show()
#############################

Is this the expected behavior?

I am running NetworkX version 1.8.dev_20120720181342.

Alejandro.

Aric Hagberg

unread,
Aug 14, 2012, 1:45:42 PM8/14/12
to networkx...@googlegroups.com
On Tue, Aug 14, 2012 at 10:42 AM, Alejandro
<alejandro...@gmail.com> wrote:
> Hi:
>
> I found that a plot title (as in plt.title('A title')) only shows in the
> figure if it is call before calling nx.draw(G).
>
> The following code illustrates this:
>
> #############################
> import networkx as nx
> import matplotlib.pyplot as plt
>
> G = nx.cycle_graph(5)
>
> plt.figure()
> nx.draw(G)
> plt.title('A title')
>
> plt.figure()
> plt.title('A title')
> nx.draw(G)
>
> plt.show()
> #############################
>
> Is this the expected behavior?

Yes, we turn the axis off with calls nx.draw() so you won't be able to
draw any axis or plot titles.
You can use instead nx.draw_networkx() which doesn't do that.

Aric
Reply all
Reply to author
Forward
0 new messages