Skip to main content

a module to beautify your python plot or terminal text.

Project description

INTRODUCTION

pymeli.為美麗而生

pymeili is a module to beautify your python plot or terminal text with more simple way. the design idea is from Navigraph aeronautical chart.

IMPORTANT

Before using this module, you need to install font-packages: https://dwl.freefontsfamily.com/download/futura/; moving the font file to installed module folder, for instance: C:\Users\Username\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymeili

For more information and instruction, please go to: https://github.com/VVVICTORZHOU/resources.git or you can just download the font file from the link above.

There still exist some bugs in this module, if you find any, please contact me by email: vichouro@gmail.com . Thank you. Some function reported bugs have added the caution hint when called.

INSTALLATION

  • Install guide: (run on your powershell or cmd)

    pip install pymeili

  • Update guide: (run on your powershell or cmd)

    pip install --upgrade pymeili

    or directly run the python script below:

    from pymeili import upgrade
    

USAGE


Beautify Your Plot

First of all, you need to import the package:

from pymeili import beautifyplot as bplt

Then, you can use the function beautifyplot to beautify your plot. Unlike matplotlib.pyplot, you don't need to create a figure and axes object. When you begin to plot, set the figsize to initialize your canvas by using initplot function. For instance:

from pymeili import beautifyplot as bplt
bplt.initplot(figsize=(10, 5))

You can set up the theme of your plot in the same function, the theme style can be 'default' or 'dark'. For instance, if you want to create a subplot with dark theme, you can use the code below:

from pymeili import beautifyplot as bplt
subplot = bplt.initsubplots(2, 1, figsize=(10, 6), style='dark')

where nrows=2, ncols=1 in this case.

Now, you can plot your data in your canvas. For instance, if you want to plot a line chart, you can use the code below:

# import the packages
from pymeili import beautifyplot as bplt
import numpy as np

# set the x and y axis data
x = np.linspace(0, 2*np.pi, 100)
y = np.linspace(0, 2*np.pi, 100)

# plot the line chart
bplt.initplot(figsize=(10, 5), style='default')
bplt.plot(x, np.sin(x), label='sin')
bplt.plot(x, np.cos(x), label='cos')
bplt.title('test')
bplt.xtick(np.linspace(0, 2*np.pi, 5), ['0', 'pi/2', 'pi', '3pi/2', '2pi'])
bplt.ytick(np.linspace(-1, 1, 5), ['1', '0.5', '0', '-0.5', '-1'])
bplt.xlabel('x')
bplt.ylabel('y')
bplt.legend()
bplt.spines()
bplt.twinx()
bplt.grid()
bplt.show()
bplt.savefig('test_1.png')
bplt.clf()

More functions are waiting for you to explore, and most syntax are similar to matplotlib.pyplot For instance, if you want to plot a contourf chart, you can use the code below:

# import the packages
from pymeili import beautifyplot as bplt
import numpy as np

# set the x and y axis data
x = np.linspace(0, 2*np.pi, 100)
y = np.linspace(0, 2*np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) + np.cos(Y)

# plot the contourf chart
subplot = bplt.initsubplots(2, 1, figsize=(8, 5))
subplot[0].righttitle('test')
subplot[0].spines()
subplot[1].contourf(X, Y, Z)
subplot[1].title('test1')
subplot[1].xlabel('x')
subplot[1].ylabel('y')
subplot[1].righttitle('test2')
subplot[1].spines()
subplot[1].twinx()
subplot.suptitle('test3')
bplt.savefig('test_2.png', dpi=300)
bplt.clf()

Another example, if you want to plot the map, you can use function Basemap like the code below:

# import the packages
from pymeili import beautifyplot as bplt

# plot the map
bplt.initplot(figsize=(18, 6), style='d') # style='d' means dark theme as well
map = bplt.Basemap(lat_0=0, lon_0=195, llcrnrlat=-15, urcrnrlat=15, llcrnrlon=90, urcrnrlon=300, resolution='l')
map.drawparallels(np.arange(-15., 15., 5.), labels=[0, 0, 0, 0], fontsize=10, linewidth=0.3, alpha=0.2)
map.drawmeridians(np.arange(90., 300., 5.), labels=[0, 0, 0, 0], fontsize=10, linewidth=0.3, alpha=0.2)
map.fillcontinents()
map.drawrivers()
bplt.axhline(-5, color='2', linewidth=3.5)
bplt.xlabel('Longitude', fontsize=14)
bplt.ylabel('Latitude', fontsize=14)
bplt.spines()
bplt.xticks([90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300], ['90°E', '105°E', '120°E', '135°E', '150°E', '165°E', '180°', '165°W', '150°W', '135°W', '120°W', '105°W', '90°W', '75°W', '60°W'])
bplt.yticks([-15, -10, -5, 0, 5, 10, 15], ['15°S', '10°S', '5°S', '0°', '5°N', '10°N', '15°N'])
bplt.lefttitle('FIGURE 1', fontsize=15)
bplt.righttitle('Maritime Continent Zone', fontsize=15)
bplt.savefig('test_3.png', dpi=300)

You can find out that the syntax will be more simple and clear. Enjoy it!

In your code, when the system does not find the font file, it will raise an error. You can use the function redirectfontfolder to redirect the font folder which contains the font file. For instance: if you have moved the font file to the folder C:\Users\Username\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymeili, you can use the code below:

from pymeili import beautifyplot as bplt

path = 'C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pymeili'
bplt.redirectfontfolder(path)

By the way, if you do not know the default fontpath, try to use the function below:

from pymeili import beautifyplot as bplt

bplt.inspectfontfolder()

The system will print the default fontpath in your terminal.

Beautify Your Terminal Text

First of all, you need to import the package:

from pymeili import beautifyterminal as btml

Then, you can use the function bprint to beautify your terminal text. For instance:

from pymeili import beautifyterminal as btml
from pymeili import beautifyterminal.bprint as bp

bp.bprint('Hello World', bg.CYAN, fg.BOLD, end=' ')

add the bg (background) or fg (foreground) color to your output text. To know which style you can use, try to use the function below:

from pymeili import beautifyterminal as btml

btml.inspectfg()

btml.inspectbg()

Very simple, right? Enjoy it!

CHANGE LOG


0.0.1 (25/07/2023)

  • First Release

0.0.2 (25/07/2023)

  • Add Font Packages

0.0.10 (25/07/2023)

  • Fix Some Problems

0.1.0 (26/07/2023)

  • Add Subplot Function

0.1.3 (26/07/2023)

  • Fix Some Minor Problems

0.1.5 (27/07/2023)

  • Add Basic Basemap Function, fix some problems

0.1.6 (27/07/2023)

  • Fix Some Problems, add common raise function

0.1.7 (27/07/2023)

  • Fix Some Minor Problems

0.1.8 (31/07/2023)

  • Fix Some Minor Problems, add new cmap '35'

0.2.0 (21/08/2023)

  • Fix Some Minor Problems, add redirectfontfolder function

0.2.1 (21/08/2023)

  • Revise the description of the package

0.2.2 (21/08/2023)

  • Revise the description of the package

0.2.3 (21/08/2023)

  • Add usage description of the package

0.2.4 (21/08/2023)

  • Fix Some Minor Problems

0.2.5 (22/08/2023)

  • Fix Some Minor Problems

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pymeili-0.2.5.tar.gz (98.7 kB view details)

Uploaded Source

File details

Details for the file pymeili-0.2.5.tar.gz.

File metadata

  • Download URL: pymeili-0.2.5.tar.gz
  • Upload date:
  • Size: 98.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pymeili-0.2.5.tar.gz
Algorithm Hash digest
SHA256 14783df27f8f7bc05197dcfc5cb163f1538e5d401455241d66350172ce1a9e21
MD5 54adc2eb246aaf1961800309dab40c13
BLAKE2b-256 8a38b8ed96097ec44db02e27be7b97c74af9255bfea58a29a1ca40bf55b3d841

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