python - Matplotlib inset graph scaling, coloring, -
python - Matplotlib inset graph scaling, coloring, -
been fiddling insets graphs in matplotlib , have tried multiple posts , threads solve close no cigarr. work ended here:
import pandas pd import numpy np import matplotlib.pyplot plt %matplotlib inline df1 = pd.dataframe(np.random.randn(10, 3), columns = ['a', 'b', 'c']) df2 = pd.dataframe(range(3, 13), columns = ['new index']) df = df1.join(df2) #this fastest way come df = df.set_index(['new index']) #set new index column in dataframe #trying add together zoomed in insets %matplotlib inline ax1 = df.plot() plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) plt.xlim([3,12]) plt.gca().invert_xaxis() #need inverted axis c = plt.axes([0.15, 0.6, .2, .2]) plt.plot(df[::-1]) #invert axis here plt.title('zoomed a') plt.setp(c, xlim=(1,2),ylim=(-1.5, 1.5), xticks=[1, 2], yticks=[]) plt.show()
and questions are:
how alter linestyle or color 2 of lines , not other , have matching in inset? why "ticks" x in inset based on actual index , not 'new index'? can changed? same question why "zoom in" based on actual index , not 'new index'? lets want "zoom in" limiting x scale setting xlim=(1,2). there improve ways it, because seems gives false results. python pandas matplotlib ipython
Comments
Post a Comment