Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
I am a hobbyist learning what python can do (and I am enjoying how much python can do!).
When drawing a circularnetworkx
graph, that has arc3connectionstyle
edges, I noticed that the graph "shrank" when I set a high value forrad. 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' whenrad 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 theylim 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 nximport matplotlib.pyplot as pltshop_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()