You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a hobbyist learning what python can do (and I am enjoying how much python can do!).
When drawing a circular networkx graph, that has arc3 connectionstyle edges, I noticed that the graph "shrank" when I set a high value for rad. Looking deeper, the graph had not shrunk. The x-axis and y-axis had lengthened.
Please refer to the graphs plotted by the code below.
I started with the top-left graph ('low-rad' of 0.5 and not having to set_ylim).
The top-right graph is the graph that 'shrank' when rad was set 'high' (rad=1).
Next, I manually set_ylim for the bottom two graphs.
The bottom-left graph looks like the top-left graph (I estimated the values for the ylim so that they look similar).
The bottom-right graph shows the intended 'high-rad' graph (the edges are high-arched).
Notice the axis ticks of each graph and compare the graphs' x-axis and y-axis data intervals. This suggests that matplotlib treats the 'high-rad' graphs as bigger than how human sees it. If the ticks were not there, I would not have known that the axis had lengthened (networkx switches off the ticks for x-axis and y-axis).
The expected outcome is the graph in the bottom right, without having to set (y-)axis limit (and without axis ticks).
I am using python 3.7.7 and matpotlib 3.2.2.
Thank you.
import networkx as nx
import matplotlib.pyplot as plt
shop_journey = [(1,2,3,4,5,6,7,8,9,10,11,12),(1,7),(7,1)]
G = nx.MultiDiGraph()
for journey in shop_journey:
if len(journey) > 1:
nx.add_path(G,journey)
def circle_pattern(ax,connectionstyle,bottom,top):
pos=nx.circular_layout(G)
nx.draw_networkx(
G,
pos=pos,
connectionstyle=connectionstyle,
ax=ax
)
ax.axis('equal')
y1,y2 = tuple(ax.yaxis.get_data_interval())
x1,x2 = tuple(ax.xaxis.get_data_interval())
title='{}\nX-axis data interval: {},{}\nY-axis data interval: {},{}\nY-limits: {},{}'.format(
connectionstyle,
round(x1,1),round(x2,1),
round(y1,1),round(y2,1),
bottom,top
)
ax.set_title(label=title)
ax.set_ylim(bottom,top)
ax.tick_params(left=True,bottom=True,labelleft=True,labelbottom=True)
fig,axs = plt.subplots(2,2,figsize=(9,9))
circle_pattern(axs[0,0],"arc3,rad=0.5",None,None)
circle_pattern(axs[0,1],"arc3,rad=1",None,None)
circle_pattern(axs[1,0],"arc3,rad=0.5",-1.5,1.5)
circle_pattern(axs[1,1],"arc3,rad=1",-1.5,1.5)
plt.subplots_adjust(hspace=0.9)
plt.show()
The text was updated successfully, but these errors were encountered:
My apologies! @dstansby, I admit the example was not simplified enough.
I have looked into the source code of networkx but I am unable to easily modify my first example, to only use matplotlib. So I have attached here a different example to show the same issue.
I looked into the networkx functions in the code I posted above. The source code (networkx.drawing.nx_pylab) calls the FancyArrowPatch from matplotlib.patches. As you know, FancyArrowPatch takes connectionstyle.
Please refer to the graph plotted by the code below. It uses only matplotlib.
Notice how the y-axis lengthens when the curvature of the line increases. The line bulges downwards, but the bottom y-lim decreases so much that the line stays near the 'ceiling' of the plot.
I do not know how the bottom y-lim would reduce so much more than the curve. The y-axis data interval also lengthens so much that it suggests there is 'invisible' data below the curve.
The expected outcome is the line (or curve) stays in the middle of the plot (without having to set y-lim).
I am a hobbyist learning what python can do (and I am enjoying how much python can do!).
When drawing a circular
networkx
graph, that has arc3connectionstyle
edges, I noticed that the graph "shrank" when I set a high value for rad. Looking deeper, the graph had not shrunk. The x-axis and y-axis had lengthened.Please refer to the graphs plotted by the code below.
I started with the top-left graph ('low-rad' of 0.5 and not having to set_ylim).
The top-right graph is the graph that 'shrank' when rad was set 'high' (rad=1).
Next, I manually set_ylim for the bottom two graphs.
The bottom-left graph looks like the top-left graph (I estimated the values for the ylim so that they look similar).
The bottom-right graph shows the intended 'high-rad' graph (the edges are high-arched).
Notice the axis ticks of each graph and compare the graphs' x-axis and y-axis data intervals. This suggests that matplotlib treats the 'high-rad' graphs as bigger than how human sees it. If the ticks were not there, I would not have known that the axis had lengthened (
networkx
switches off the ticks for x-axis and y-axis).The expected outcome is the graph in the bottom right, without having to set (y-)axis limit (and without axis ticks).
I am using python 3.7.7 and matpotlib 3.2.2.
Thank you.
The text was updated successfully, but these errors were encountered: