Skip to main content

A scientific style plot tool based on matplotlib.

Project description

sciplot

A scientific style plot tool based on matplotlib.

Style demonstration

Features

  • Plot 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.

Install

Install by pip:

pip install diegoplot

Import the package:

from diegoplot import diegoplot
diegoplot.DiegoPlot()

Or, you can copy the diegoplot.py file into the folder of your project and import it by:

import diegoplot
diegoplot.DiegoPlot()

mini demo

To preview the figure comes from your data, the fast way is just SciPlot(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.
import numpy as np
from diegoplot import diegoplot

x = np.linspace(0, 10, 100)
y = np.array([(a + 1) * np.sin(x) for a in range(4)])
diegoplot.DiegoPlot(x, y,
                    label=['x-axis', 'y-axis'],
                    legend=['line {}'.format(n + 1) for n in range(4)],
                    tag='(a)')

The data, x and y, could be in different kinds of.

  • A single curve like x = [x1, x2, ...] and y = [y1, y2, ...] is fine.
  • Multiple curves with same x coordinates should be given like x = [x1, x2, ...] and y = [[curve1_y1, curve1_y2, ...], [curve2_y1, curve2_y2, ...], ...]
  • Of course, multiple curves can have different x coordinates, just give both x and y in the form of [[...],[...],...]. And make sure they are within the same length.

Fine tuning

A fine-tuning is needed to generate the final product. In this case, you are supposed to use the sciplot in 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.
import numpy as np
from diegoplot import diegoplot

x = np.linspace(0, 10, 30)
y = np.array([(a + 1) * np.sin(x) for a in range(4)])
dp = diegoplot.DiegoPlot()
dp.manual_load(x, y, ['x-axis', 'y-axis'], ['line {}'.format(n + 1) for n in range(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 before show(). Change the range of axis is often used to make curves looks better, or avoid interfering with legend and tag. This is change by sp.ax, which is exactly the axis object of matplotlib. You should see the documentation of matplotlib for more, but I'll list some useful functions.

# axis span range
dp.ax.set_xlim([0, 1])
dp.ax.set_ylim([0, 1])
# where are the scale lines
dp.ax.set_xticks([0, 0.5, 1])
dp.ax.set_yticks([0, 0.5, 1])
# plot text, lines, annotates
dp.ax.text()
dp.ax.hline()
dp.ax.vline()
dp.ax.annotate()
# create another y-axis
ax2 = dp.ax.twinx()  

Load data

Data can be load in different ways. They can be load manually by sp.manual_load(), or load form txt, npz, and csv files. For data generated by python, npz is strongly recommended. sciplot have 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diegoplot-1.2.tar.gz (221.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diegoplot-1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file diegoplot-1.2.tar.gz.

File metadata

  • Download URL: diegoplot-1.2.tar.gz
  • Upload date:
  • Size: 221.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.0

File hashes

Hashes for diegoplot-1.2.tar.gz
Algorithm Hash digest
SHA256 9de49bbaf84f2f8c339683fded201ec190294bf319b0c40ae790663a9d28f078
MD5 881bd1c919d09399c823b08b7ea61da9
BLAKE2b-256 42c6c143ba49f87897fdf625083d939ad56f3de0862cc976d8fd7ceca50b9c66

See more details on using hashes here.

File details

Details for the file diegoplot-1.2-py3-none-any.whl.

File metadata

  • Download URL: diegoplot-1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.0

File hashes

Hashes for diegoplot-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bcc853ab4768883792be99915deb2b3513f6dd5bb6b08badf9ad152e5654d0c9
MD5 653fbfaed3c64ae8de42f815cb1e6d9b
BLAKE2b-256 37c3dfb212119c1bed161ad466637138164640028eeffa7637ea0c903f36d4ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page