[Matplotlib-users] Fwd: Fwd: matplotlib - extend x-axis labels and scaling problem

Duncan Kerr duncan.kerr at live.com
Wed Mar 25 07:05:03 EDT 2020


>
> I have a couple of issues, trying to plot two y axes.  How do I
>
> make grid cover whole area of plot
>
> make xaxis labels go all way to right
>
> make both y axes use same scale
>
> get a legend for both plots onto the graph.
>
> my graph and code are as follows:
>
> #!c:/python/python import sys
> import numpyas np
> import pandasas pd
> import matplotlibas mpl
> import matplotlib.pyplotas plt
> import seabornas sns
> import warnings;
>
> warnings.filterwarnings(action='once')
>
> plt.style.use('seaborn-whitegrid')
> sns.set_style("white")
>
> cl1='red' cl2='blue' cl3='grey' print("expected title filter1 filter3 file1 file2")
> print("called with "+sys.argv[1]+","+sys.argv[2]+","+sys.argv[3]+","+sys.argv[4])
> # Version print(mpl.__version__)# > 3.0.0 print(sns.__version__)# > 0.9.0 # Import Data dfr = pd.read_csv(sys.argv[4])
> dfs = pd.read_csv(sys.argv[5])
> xyr = dfr.groupby(['c1']).count()['c2']
> xys = dfs.groupby(['c1']).count()['c2']
>
> fig, ax = plt.subplots(1,1,figsize=(16,9),dpi=90)
>
> # print data for plots print(dfr.groupby('c1').count())
>
> dfr.groupby(['c1']).count()['c2'].plot(ax=ax,color=cl1,label='leftfilter')
>
> # Decorations # ax1 (left Y axis) ax.set_xlabel('time',color=cl3,fontsize=20)
> ax.tick_params(axis='x',rotation=0,labelcolor=cl3,labelsize=12)
> ax.set_ylabel(sys.argv[2],color=cl1,fontsize=20)
> ax.tick_params(axis='y',rotation=0,labelcolor=cl1)
> ax.grid(alpha=.4)
> s ="%s min %d max %d avg %d std %d" % (
> sys.argv[1], dfr.groupby('c1').count().min()['c2'], dfr.groupby('c1').count().max()['c2'],
> dfr.groupby('c1').count().mean()['c2'], dfs.groupby('c1').count().std()['c2'])
> ax.set_title(s,color=cl3)
>
>
> # ax2 (right Y axis) ax2 = ax.twinx()# instantiate a second axes that shares the same x-axis ax2.tick_params(axis='x',rotation=0,labelcolor=cl3,labelsize=12)
> dfs.groupby(['c1']).count()['c2'].plot(ax=ax2,color=cl2)
> ax2.set_ylabel(sys.argv[3],color=cl2,fontsize=20)
> ax2.tick_params(axis='y',labelcolor=cl2)
> fig.tight_layout()
> # place legend in good spot #plt.legend(loc=0) plt.show()
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200325/514573dc/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: decchfafllgghohe.png
Type: image/png
Size: 182519 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200325/514573dc/attachment-0001.png>


More information about the Matplotlib-users mailing list