• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Saturday, September 13, 2025
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Machine Learning

From Default Python Line Chart to Journal-High quality Infographics | by Vladimir Zhyvov | Dec, 2024

Admin by Admin
December 30, 2024
in Machine Learning
0
1b1ldtefrk29fj3tkd2r2lw.png
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


Rework boring default Matplotlib line charts into gorgeous, personalized visualizations

Vladimir Zhyvov

Towards Data Science

Cowl, picture by the Creator

Everybody who has used Matplotlib is aware of how ugly the default charts appear to be. On this sequence of posts, I’ll share some methods to make your visualizations stand out and replicate your particular person model.

We’ll begin with a easy line chart, which is broadly used. The principle spotlight will likely be including a gradient fill beneath the plot — a activity that’s not fully easy.

So, let’s dive in and stroll by means of all the important thing steps of this transformation!

Let’s make all the mandatory imports first.

import pandas as pd
import numpy as np
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib import rcParams
from matplotlib.path import Path
from matplotlib.patches import PathPatch

np.random.seed(38)

Now we have to generate pattern knowledge for our visualization. We’ll create one thing much like what inventory costs appear to be.

dates = pd.date_range(begin='2024-02-01', durations=100, freq='D')
initial_rate = 75
drift = 0.003
volatility = 0.1
returns = np.random.regular(drift, volatility, len(dates))
charges = initial_rate * np.cumprod(1 + returns)

x, y = dates, charges

Let’s examine the way it appears to be like with the default Matplotlib settings.

repair, ax = plt.subplots(figsize=(8, 4))
ax.plot(dates, charges)
ax.xaxis.set_major_locator(mdates.DayLocator(interval=30))
plt.present()
Default plot, picture by Creator

Not likely fascination, proper? However we are going to steadily make it trying higher.

  • set the title
  • set common chart parameters — measurement and font
  • putting the Y ticks to the suitable
  • altering the primary line coloration, model and width
# Common parameters
fig, ax = plt.subplots(figsize=(10, 6))
plt.title("Day by day guests", fontsize=18, coloration="black")
rcParams['font.family'] = 'DejaVu Sans'
rcParams['font.size'] = 14

# Axis Y to the suitable
ax.yaxis.tick_right()
ax.yaxis.set_label_position("proper")

# Plotting primary line
ax.plot(dates, charges, coloration='#268358', linewidth=2)

Common params utilized, picture by Creator

Alright, now it appears to be like a bit cleaner.

Now we’d like so as to add minimalistic grid to the background, take away borders for a cleaner look and take away ticks from the Y axis.

# Grid
ax.grid(coloration="grey", linestyle=(0, (10, 10)), linewidth=0.5, alpha=0.6)
ax.tick_params(axis="x", colours="black")
ax.tick_params(axis="y", left=False, labelleft=False)

# Borders
ax.spines["top"].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines["bottom"].set_color("black")
ax.spines['left'].set_color('white')
ax.spines['left'].set_linewidth(1)

# Take away ticks from axis Y
ax.tick_params(axis='y', size=0)

Grid added, picture by Creator

Now we’re including a tine esthetic element — yr close to the primary tick on the axis X. Additionally we make the font coloration of tick labels extra pale.

# Add yr to the primary date on the axis
def custom_date_formatter(t, pos, dates, x_interval):
date = dates[pos*x_interval]
if pos == 0:
return date.strftime('%d %b '%y')
else:
return date.strftime('%d %b')
ax.xaxis.set_major_formatter(ticker.FuncFormatter((lambda x, pos: custom_date_formatter(x, pos, dates=dates, x_interval=x_interval))))

# Ticks label coloration
[t.set_color('#808079') for t in ax.yaxis.get_ticklabels()]
[t.set_color('#808079') for t in ax.xaxis.get_ticklabels()]

12 months close to first date, picture by Creator

And we’re getting nearer to the trickiest second — find out how to create a gradient underneath the curve. Really there is no such thing as a such choice in Matplotlib, however we will simulate it making a gradient picture after which clipping it with the chart.

# Gradient
numeric_x = np.array([i for i in range(len(x))])
numeric_x_patch = np.append(numeric_x, max(numeric_x))
numeric_x_patch = np.append(numeric_x_patch[0], numeric_x_patch)
y_patch = np.append(y, 0)
y_patch = np.append(0, y_patch)

path = Path(np.array([numeric_x_patch, y_patch]).transpose())
patch = PathPatch(path, facecolor='none')
plt.gca().add_patch(patch)

ax.imshow(numeric_x.reshape(len(numeric_x), 1), interpolation="bicubic",
cmap=plt.cm.Greens,
origin='decrease',
alpha=0.3,
extent=[min(numeric_x), max(numeric_x), min(y_patch), max(y_patch) * 1.2],
side="auto", clip_path=patch, clip_on=True)

Gradient added, picture by Creator

Now it appears to be like clear and good. We simply want so as to add a number of particulars utilizing any editor (I want Google Slides) — title, spherical border corners and a few numeric indicators.

Remaining visualization, picture by Creator

The complete code to breed the visualization is beneath:

READ ALSO

If we use AI to do our work – what’s our job, then?

10 Python One-Liners Each Machine Studying Practitioner Ought to Know

Tags: ChartDecDefaultInfographicsJournalQualityLinePythonVladimirZhyvov

Related Posts

Mike von 2hzl3nmoozs unsplash scaled 1.jpg
Machine Learning

If we use AI to do our work – what’s our job, then?

September 13, 2025
Mlm ipc 10 python one liners ml practitioners 1024x683.png
Machine Learning

10 Python One-Liners Each Machine Studying Practitioner Ought to Know

September 12, 2025
Luna wang s01fgc mfqw unsplash 1.jpg
Machine Learning

When A Distinction Truly Makes A Distinction

September 11, 2025
Mlm ipc roc auc vs precision recall imblanced data 1024x683.png
Machine Learning

ROC AUC vs Precision-Recall for Imbalanced Knowledge

September 10, 2025
Langchain for eda build a csv sanity check agent in python.png
Machine Learning

LangChain for EDA: Construct a CSV Sanity-Examine Agent in Python

September 9, 2025
Jakub zerdzicki a 90g6ta56a unsplash scaled 1.jpg
Machine Learning

Implementing the Espresso Machine in Python

September 8, 2025
Next Post
0yqnqr1ayml9pausi.jpeg

Tips on how to Make sure the Stability of a Mannequin Utilizing Jackknife Estimation | by Paula LC | Dec, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025
Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
1da3lz S3h Cujupuolbtvw.png

Scaling Statistics: Incremental Customary Deviation in SQL with dbt | by Yuval Gorchover | Jan, 2025

January 2, 2025
0khns0 Djocjfzxyr.jpeg

Constructing Data Graphs with LLM Graph Transformer | by Tomaz Bratanic | Nov, 2024

November 5, 2024
How To Maintain Data Quality In The Supply Chain Feature.jpg

Find out how to Preserve Knowledge High quality within the Provide Chain

September 8, 2024

EDITOR'S PICK

0awxkkxwrdisjf32s.jpeg

Meet Git Stash: Your Secret Chest of Unfinished Code | by Zolzaya Luvsandorj | Oct, 2024

October 26, 2024
1efkxsinu5krp0bg Dtcflg.png

How I Created a Information Science Mission Following CRISP-DM Lifecycle | by Gustavo Santos | Nov, 2024

November 14, 2024
Wearable ai.png

Wearable AI – Implementation and Advantages in Digitalization

September 4, 2025
1m3bfi7jm Kcvkj9eijmwtg.png

Fundamentals of GANs & SMOTE for Information Augmentation | by Sunghyun Ahn | Jan, 2025

January 16, 2025

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • 5 Key Methods LLMs Can Supercharge Your Machine Studying Workflow
  • AAVE Value Reclaims $320 As TVL Metric Reveals Optimistic Divergence — What’s Subsequent?
  • Grasp Knowledge Administration: Constructing Stronger, Resilient Provide Chains
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?