<jupyter_start><jupyter_text>[Plotnine](https://plotnine.readthedocs.io/en/stable/): almost a Python clone of ggplot2 in R<jupyter_code>##############################################################################################
##############################################################################################
# "ggplot2" is a very powerful R package for data visualisation.
# In Python, you can use "plotnine" to run R codes from ggplot2, but with the Python coating.

# Also
# check out sth like this: https://github.com/yhat/ggpy
# https://pypi.org/project/ggplot/
##############################################################################################
# Example: 

# read a sample data
import os 
import pandas as pd
os.chdir('your-working-directory')
sample_data = pd.read_csv("some-data-frame.csv")

# import the plotnine package
import plotnine as p9

# make a scatter plot using "geom_point" from "ggplot2"
Test_plot = (p9.ggplot(sample_data)  +
             p9.xlim(0,0.5)   +
             p9.ylim(0,0.5)   +
             p9.coord_fixed() +
             p9.geom_point(aes('var_x','var_y'),size = 20,color='red'))

# show the plot (just like in ggplot2!)
Test_plot

# save out the figure (just like in ggplot2!)
Test_plot.save('test.png',dpi=300,width = 20, height = 20)
##############################################################################################
# Remarks: "plotnine" certainly provides a straighforward way to use "ggplot2" in Python.
#           But things like "patchwork" seems to be not possible at least by now, need to consider how to combine multiple plots.

# End
##############################################################################################<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.35297482837528604, 'fraction_numerical': 0.016018306636155607, 'mean_word_length': 5.336956521739131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '382756', 'license': 'MIT', 'n_tokens_mistral': 510, 'n_tokens_neox': 471, 'n_words': 136, 'path': 'Tutorial/2-Research-Data-Visualisations/2.8-Plotnine/ggplot2-in-python.ipynb', 'repo_name': 'GongdaLu/Python-for-Atmospheric-Scientists', 'size': '1748'}