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

If you encounter the FileNotFound error when using this module, you need to manually 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\resources

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.xticks(np.linspace(0, 2*np.pi, 5), ['0', 'pi/2', 'pi', '3pi/2', '2pi'])
bplt.yticks(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()

demo_fig_1

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\\resources'
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('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!

Beautify Your Meteogram

First of all, you need to import the package:

from pymeili import beautifymeteogram as bmet

Then, you can use the function beautifymeteogram to beautify your meteogram. For instance:

If you want to plot the Skew-T diagram (斜溫圖), also get the CAPE and CIN for your provided sounding data, suppose we have the sounding data below: pressure00z, temperature00z, dewpoint00z, windspeed00z, winddirection00z are the vertical data of 00Z

then try to use the code below:

# import the packages
from pymeili import beautifymeteogram as bmet
from matplotlib import pyplot as plt

# access the data 
... # with same shape

# 00Z plot
fig = bmet.SkewT_plot(pressure00z, temperature00z, dewpoint00z, windspeed=windspeed00z, winddirection=winddirection00z, height=height00z, lefttitle='FIGURE 1', righttitle='00Z', style='light')
plt.savefig(imagepath+'skewt00z_new.png', dpi=300, bbox_inches='tight')

# print the CAPE and CIN
print(f'CAPE:{fig.get_CAPE()}', f'CIN:{fig.get_CIN()}')

You will get the figure quite simple and clear. Note that hodograph will be added if you provide the wind... and height data, you can turn off by using hodograph=False in the function SkewT_plot. Other functions are under development. 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 (21/08/2023)

  • Add beautifyterminal module

0.2.6 (22/08/2023)

  • Fix Some Problems

0.2.7 (23/08/2023)

  • Some Minor Details Change

0.2.8 (24/08/2023)

  • Fix some colorbar problems

0.2.14 (24/08/2023)

  • Fix Some Minor Problems

0.2.15 (25/08/2023)

  • Fix fontfiles install problem

0.2.20 (02/09/2023)

  • Fix Some Minor Problems

0.3.0 (02/09/2023)

  • Solve the font problem that you don't have to manually install the font now

0.3.2 (02/09/2023)

  • Fix Some Minor Problems

0.3.3 (04/09/2023)

  • Fix Some Minor Problems

0.3.5 (05/09/2023)

  • Standardize description of the output hint

0.3.6 (09/09/2023)

  • New feature: add 'beautifymeteogram' for meteological plot (alpha edition)

0.3.7 (09/09/2023)

  • Fix Some Minor Problems

0.3.10 (10/09/2023)

  • Fix the theme problems of the meteogram
  • Add hodograph function in the skew-T plot

0.3.11 (10/09/2023)

  • Fix Some Details
  • Add the function 'fontprop' to get the font properties

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.3.11.tar.gz (239.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pymeili-0.3.11.tar.gz
Algorithm Hash digest
SHA256 b385b08b98d3a670f18ca452e160ba57d797040abe18582b01d0cb6beb77f3ec
MD5 b1f7599024da2ace33dfbcb77af7e776
BLAKE2b-256 faa604500241876f91a5153b28f7a8858b87ec73ede70f1eaa3c4e3367d924f6

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