python - How to make matplotlib graphs look professionally done like this? -
default matplotlib graphs unattractive , unprofessional. tried out couple of packages include seaborn prettyplotlib both of these barely improves styles.
so far i've gotten following using seaborn package:

below appearance i'm looking far cry above:

notice following niceness in 2nd example:
- area under graph filled more eye pleasing color.
- the graph line thinker , nicely stands out.
- axis lines thinker , again nicely stands out.
- area under curve transparent.
- x-axis tick marks more denser.
my questions are: recognize above kind of popular theme or style can use in matplotlib? or if can use package? failing that, there anyway set style global preference? failing that, possible in matlibplot?
thanks!
this matter of taste, , matter of target audience. matplotlib tries produce clear illustrations scientific purposes. - - compromise, , illustrations not print in magazine or show in advertisement.
there news , bad news matplotlib in sense.
bad news:
- there no single magical command or package create beautiful plots
matplotlib.
good news:
- there simple ways change default settings, see: http://matplotlib.org/users/customizing.html
- the object model enables user change , introduce complex new features.
- the source code available, , can changed quite user.
in opinion difficult thing decide want. doing want easier, though there steepish learning curve in beginning.
just example:
import numpy np import matplotlib.pyplot plt # create fictive access data hour xdata = np.arange(25) ydata = np.random.randint(10, 20, 25) ydata[24] = ydata[0] # let make simple graph fig = plt.figure(figsize=[7,5]) ax = plt.subplot(111) l = ax.fill_between(xdata, ydata) # set basic properties ax.set_xlabel('time of posting (us est)') ax.set_ylabel('percentage of frontpaged submissions') ax.set_title('likelihood of reaching frontpage') # set limits ax.set_xlim(0, 24) ax.set_ylim(6, 24) # set grid on ax.grid('on') (just comment: x-axis limits in original image not take cyclicity of data account.)
this give this:

it easy understand need lot of changes in order able show less-engineering-minded audience. @ least:
- make fill transparent , less offensive in colour
- make line thicker
- change line colour
- add more ticks x axis
- change fonts of titles
# change fill blueish color opacity .3 l.set_facecolors([[.5,.5,.8,.3]]) # change edge color (bluish , transparentish) , thickness l.set_edgecolors([[0, 0, .5, .3]]) l.set_linewidths([3]) # add more ticks ax.set_xticks(np.arange(25)) # remove tick marks ax.xaxis.set_tick_params(size=0) ax.yaxis.set_tick_params(size=0) # change color of top , right spines opaque gray ax.spines['right'].set_color((.8,.8,.8)) ax.spines['top'].set_color((.8,.8,.8)) # tweak axis labels xlab = ax.xaxis.get_label() ylab = ax.yaxis.get_label() xlab.set_style('italic') xlab.set_size(10) ylab.set_style('italic') ylab.set_size(10) # tweak title ttl = ax.title ttl.set_weight('bold') now have:

this not in question, can tuned towards direction. many of things set here can set defaults matplotlib. maybe gives idea of how change things in plots.
Comments
Post a Comment