Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Matplotlib wrapper with some customisations to plot pretty graphs with very few lines of code. Plots can be updated using an interactive GUI.

License

NotificationsYou must be signed in to change notification settings

tfpf/graph-plot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Customplot is a wrapper around Matplotlib. It can be used to plot beautiful,publication-quality graphs, which can optionally be controlled interactively.

Interactive Screengrab

I mainly wrote this to plot graphs of functions in the Cartesian plane, but itcan be used for many other things, too. (Take a gander at thegallery.)

Requirements

NameVersionComment
Python3.8Required
Matplotlib3.3.4Required
NumPy1.17Required
curses2.2Optional

These requirements are not strict. Slightly older versions should also be okay.

Usage

Calllimit andpolish on your Matplotlib axes instance before and afterplotting, respectively. Check the fileexamples.py for details. You can runit using the command

$python3 examples.py

to see how things work.

A good way to start plotting your own graphs might be to copy parts of the codeinexamples.py to another file, make modifications to that file, and run it.

Notes

General

Customplot cannot replace Matplotlib or Pyplot. It just does a few things whichmake the plot look pretty (to my eyes, at least). For sufficiently complicatedplots, you may have to use functions of Matplotlib or Pyplot directly.

Onlyrectilinear,polar and3d projections of Matplotlib axes aresupported. Other projections can also be used, but their beautification may nothappen automatically.

Interactive Plots

As seen in the image above, you can interactively adjust some plot elements ofall Matplotlib axes in a figure (provided that the curses module is installedand available). To do so, just usecustomplot.show(fig) (fig being theMatplotlib figure instance) instead ofplt.show(). More details can be foundinexamples.py.

Matplotlib is not thread-safe! Since the curses GUI is run in a separatethread, you may occasionally have to trigger additional GUI events (e.g.resizing the figure window) to have the desired effect.

Fonts

Using a good font can significantly improve the appearance of your plot. (Checkout thegallery. The font used in those plots isCochineal.)

In case you want nothing to do with fonts, you can ignore this sectionentirely.

Using a Packaged Font

Some fonts are packaged with Matplotlib; you can choose one of them. Mysuggestion is a STIX font. To use it, add the following lines to the filelight.mplstyle (you can find this file in thestyles directory).

font.family:STIXGeneralmathtext.fontset:stix

Computer Modern is also available, but I do not recommend using it, because itcannot render minus signs in normal text.

Using a Custom Font

Let's say you want to use Libre Baskerville.

  • Download and install Libre Baskerville. (It will probably be freely availableas a package containing multiple font files.) On most operating systems, youcan simply unzip the package and double-click on each of the font files toinstall it.
  • Find out where Matplotlib stores its cache.
$python3>>> import matplotlib as mpl>>> mpl.get_cachedir()
  • Delete all font-related cache files in that location.
  • Add the following lines to the filelight.mplstyle.
font.family:LibreBaskervillemathtext.bf:LibreBaskerville:boldmathtext.it:LibreBaskerville:italicmathtext.rm:LibreBaskervillemathtext.fontset:custommathtext.fallback:stixmathtext.default:it

Subplots

Sometimes, subplots (multiple plots in a single figure) don't look prettybecause elements from adjacent plots overlap with each other. To get aroundthis problem, you can interactively adjust the spacing by using the 'Configuresubplots' option in the navigation toolbar of the figure.

After doing this, un-maximise and maximise the figure window. As a result,anything that needs to be redrawn will be redrawn.

DPI Settings

If the plot doesn't look quite right, try playing around with the DPI parameterbefore adjusting anything else. In the filelight.mplstyle, search forfigure.dpi and change the value next to it.

What the best value is depends on the resolution of your screen as well as itsscaling factor. In my experience, when the scaling factor is 1, a value of 192produces pretty graphs on a 1080p screen, while a 768p screen may requiresetting it to 135 or so. On a 720p screen, 128 should work well. (Reducing theDPI will also reduce the quality of the image. Proceed with caution.)

Essential and Jump Discontinuities

There are two types of discontinuities most graph plotters struggle with:

  • essential discontinuities (like those in the graph ofy = tanx); and
  • jump discontinuities (like those in the graph ofy = sgnx).

A vertical line is automatically drawn at each point of discontinuity. This issimply a result of the plotting algorithm used by graph plotters. If thishappens in your plot, try using thesanitise function with a suitable valueofmaximum_diff. (A demonstration can be found inexamples.py.)

Gallery

Function
Functions
Astroid
Folium of Descartes
Lemniscate
Population Distribution
Potentiometric Titration
Refractometry
Export Revenue
Oxygen Parameters

About

Matplotlib wrapper with some customisations to plot pretty graphs with very few lines of code. Plots can be updated using an interactive GUI.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp