Package: diegoplot
sciplotA scientific style plot tool based on matplotlib.FeaturesPlot figures for scientific articles painlessly, with right size, font, and others.Quick preview, quick as hell.Supporting three built in styles and custom style.(a) Color cycle, looks cleaner for online journals.(b) Color and marker cycle, support black-and-white view.(c) Line style and marker cycle, support up to 16 lines without repeat.(d) Custom style, easy to set and useful when you got several groups of curves.InstallInstall by pip:pipinstalldiegoplotImport the package:fromdiegoplotimportdiegoplotdiegoplot.DiegoPlot()Or, you can copy thediegoplot.pyfile into the folder of your project and import it by:importdiegoplotdiegoplot.DiegoPlot()mini demoTo preview the figure comes from your data, the fast way is justSciPlot(x, y).
No configurations needed, you'll get a pretty much finished figure.
Optionally, label, legend, and tag could be given as keyword arguments.# This demo gives the figure (a) above.importnumpyasnpfromdiegoplotimportdiegoplotx=np.linspace(0,10,100)y=np.array([(a+1)*np.sin(x)forainrange(4)])diegoplot.DiegoPlot(x,y,label=['x-axis','y-axis'],legend=['line{}'.format(n+1)forninrange(4)],tag='(a)')The data,xandy, could be in different kinds of.A single curve likex = [x1, x2, ...]andy = [y1, y2, ...]is fine.Multiple curves with samexcoordinates should be given likex = [x1, x2, ...]andy = [[curve1_y1, curve1_y2, ...], [curve2_y1, curve2_y2, ...], ...]Of course, multiple curves can have differentxcoordinates,
just give bothxandyin the form of[[...],[...],...].
And make sure they are within the same length.Fine tuningA fine-tuning is needed to generate the final product.
In this case, you are supposed to use thesciplotin a detailed way.
There are up to 6 steps: load data, plot data, plot label, plot legend, plot tag, and show.# This demo gives the figure (b) above.importnumpyasnpfromdiegoplotimportdiegoplotx=np.linspace(0,10,30)y=np.array([(a+1)*np.sin(x)forainrange(4)])dp=diegoplot.DiegoPlot()dp.manual_load(x,y,['x-axis','y-axis'],['line{}'.format(n+1)forninrange(4)])dp.plot_data(1)# 1 for style 1. Currently, there are 3 built in styles, 0, 1, and 2.# Corresponding to figure (a), (b), and (c).dp.plot_label()# Optionally, label can be given here as a parameter.dp.plot_legend()# Optionally, legend can be given here as a parameter.dp.plot_tag('(b)')# The position of the tag is configurable, see annotation of this function.dp.show()# Comes with an auto-tight function. Pass through auto_tight=False to disable it.Apart those steps means you can write your own, customized ones. Or add some operations beforeshow().
Change the range of axis is often used to make curves looks better, or avoid interfering with legend and tag.
This is change bysp.ax, which is exactly the axis object ofmatplotlib.
You should see the documentation ofmatplotlibfor more, but I'll list some useful functions.# axis span rangedp.ax.set_xlim([0,1])dp.ax.set_ylim([0,1])# where are the scale linesdp.ax.set_xticks([0,0.5,1])dp.ax.set_yticks([0,0.5,1])# plot text, lines, annotatesdp.ax.text()dp.ax.hline()dp.ax.vline()dp.ax.annotate()# create another y-axisax2=dp.ax.twinx()Load dataData can be load in different ways.
They can be load manually bysp.manual_load(), or load formtxt,npz, andcsvfiles.
For data generated by python,npzis strongly recommended.sciplothave three built-in functions to load these data:load_npz(),load_txt(),load_csv().
These functions are coding for my use case.
Annotations are given about how the data are organized.