How to create basic and small grids with various Linestyles in Python

I am currently using matplotlib.pyplot to create graphs and want the main meshes to be solid and black, and the secondary meshes to be gray or dashed. in the grid which = both / major / mine, and then the color and linestyle are defined simply by linestyle, is there a way to specify only a small linestyle?

Relevant code i still

 plt.plot(current, counts, 'rd', markersize=8) plt.yscale('log') plt.grid(b=True, which='both', color='0.65',linestyle='-') 
+80
python matplotlib
Feb 03 2018-12-12T00:
source share
2 answers

Actually, it is as simple as installing major and minor separately:

 In [9]: plot([23, 456, 676, 89, 906, 34, 2345]) Out[9]: [<matplotlib.lines.Line2D at 0x6112f90>] In [10]: yscale('log') In [11]: grid(b=True, which='major', color='b', linestyle='-') In [12]: grid(b=True, which='minor', color='r', linestyle='--') 

The information obtained with small grids is that you should also include minor marks. In the above code, this is done using yscale('log') , but it can also be done using plt.minorticks_on() .

enter image description here

+116
Feb 05 2018-12-12T00:
source share

A simple DIY way would be to make the grid yourself:

 import matplotlib.pyplot as plt fig=plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3],[2,3,4],'ro') for xmaj in ax.xaxis.get_majorticklocs(): ax.axvline(x=xmaj,ls='-') for xmin in ax.xaxis.get_minorticklocs(): ax.axvline(x=xmin,ls='--') for ymaj in ax.yaxis.get_majorticklocs(): ax.axhline(y=ymaj,ls='-') for ymin in ax.yaxis.get_minorticklocs(): ax.axhline(y=ymin,ls='--') plt.show() 
+18
Feb 03 2018-12-12T00:
source share



All Articles