DelphiFeeds.com

  • Dashboard
  • Popular Stories
  • Trending Stories
  • Feeds
  • Login
Trending now

Using Apilayer REST APIs from Delphi

Using Apilayer REST APIs from Delphi

Delphi Offers Massive Productivity Boost Over WPF And Electron

7 Tips For Learning To Build Powerful Windows GUI Apps Using Python And Delphi

Create Enterprise-Grade Grid Based Desktop Applications 10x Faster With X-Files Components

Quickly Learn How To Fetch A Table Using FireDAC In This IFDPhysCommand Delphi Sample

Tutorial: Introduction To C++ Parallel Compilation With TwineCompile

Easily Integrate Exception Handling Into Your Python GUI Apps Through Delphi

Delphi debugging tip: keep an eye on a object field of an object that will ...

Distinguer les processeurs Intel des processeurs Apple Silicon depuis nos programmes

Powerful Award-Winning Windows UI Toolkit For Delphi And C++Builder

Quickly Access Windows System Info In Your Delphi Application With Excellent Component Suite

Build Visual Stunning Apps Faster With Less Code Using RAD Studio Architect Edition

Introduction To Modern C++ With Tutorials

TMS WEB Core for Visual Studio Code v1.2 released!

Learn To Build A Python GUI For Working with 2D Graphics And The Matplotlib Library In A Delphi Windows App

1
Nataliia Fedchenko Nataliia Fedchenko 2 months ago in C++, C++ Builder, Code, Delphi, programming, Python, python gui, python4delphi, windows 0

Drawing graphics programmatically is a very popular task these days. You can easily solve it using Matplotlib library with Python4Delphi (P4D). P4D is a free set of instruments that allows you to work with Python scripts, modules and types in Delphi. In this post, we will look at how to run Matplotlib library using Python for Delphi.

With Delphi and C++Builder and Python4Delphi, you can build Python GUI apps for Windows using various Python libraries. Open project Demo1 to run the Python script in Python for Delphi. Use Memo1 for Python script and Memo2 for results. Click Execute button for running the script. Download Demo1 source from GitHub. If you run into a floating point division error when executing the code run MaskFPUExceptions(True); before you call ExecStrings.

procedure TForm1.Button1Click(Sender: TObject);
begin
 PythonEngine1.ExecStrings( Memo1.Lines );
end;

Python Matplotlib library provides various tools for working with 2D graphics. With this library, you can create graphics, customize legends, style sheets, color schemes, and manipulate images. There are examples of code from the Matplotlib below.

Draw a plot

You can draw very simple plots with Mathplotlib. Or, if you want, you can change the shape and color of the points in the graphic in different ways. In the following example, we will draw the green triangular points using the argument ‘g^’  in function plot().

import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0., 5., 0.2)
plt.plot(t, 'g^')
plt.show()

matplotlib3-3

Stacked bar chart

In this example, we show how to draw a stacked bar plot. We will use the function bar() twice. We need to pass to this function such parameters as labels, values of various categories that need to be displayed, names of labels. Finally, we will set such graphic parameters as title, y-label.

import matplotlib.pyplot as plt
labels = [1, 2, 3, 4, 5]
cat1_means = [14, 39, 30, 19, 54]
cat2_means = [43, 62, 52, 51, 29]
width = 0.35
fig, ax = plt.subplots()
ax.bar(labels, cat1_means, width, label='Cat1')
ax.bar(labels, cat2_means, width, bottom=cat1_means, label='Cat2')
ax.set_ylabel('Scores')
ax.set_title('Scores by product cutegories')
ax.legend()
plt.show()

matplotlib1-4

Draw curves and fill the area

In this example, we use the function plot() again to build a graphic of cos(x). Then we fill the area in green color between two curves using function fill_between(). Pass parameters x, y1 and y2 to determine the curve and exclude some horizontal regions from being filled using parameter where.

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.arange(0, 7 * np.pi, 0.1)
y = np.cos(x)
ax.plot(x, y, color='black')

ax.fill_between(x, 0, 1, where=y > 0.75,
                color='green', alpha=0.5, transform=ax.get_xaxis_transform())
plt.show()

matplotlib2-2

We got acquainted with some of the Matplotlib library’s features. Go here, download this library and draw your beautiful graphs. Download Python4Delphi and build Python GUIs for Windows using Delphi easily.

Trending Stories

  • Using Apilayer REST APIs from Delphi

  • Delphi Offers Massive Productivity Boost Over WPF And Electron

  • 7 Tips For Learning To Build Powerful Windows GUI Apps...

  • Create Enterprise-Grade Grid Based Desktop Applications 10x Faster With X-Files...

  • Quickly Learn How To Fetch A Table Using FireDAC In...

Embarcadero GetIt

  • Brook Framework

    Microframework which helps to develop web Pascal applications.

  • Trial - TMS Scripter

    Add the ultimate flexibility and power into your apps with native Pascal or Basic scripting and […]

  • Trial - TMS VCL Chart

    DB-aware and non DB-aware feature-rich charting components for business, statistical, financial […]

  • Trial - TMS VCL Cloud Pack

    TMS VCL Cloud Pack is a Delphi and C++Builder component library to seamlessly use all major cloud […]

  • Trial - TMS VCL UI Pack

    Create modern-looking & feature-rich Windows applications faster with well over 600 components […]

  • Learn Delphi Programming
  • Learn C++
  • Embarcadero Blogs
  • BeginEnd.net
  • Python GUI
  • Firebird News
  • Torry’s Delphi Pages
Copyright DelphiFeeds.com 2021. All Rights Reserved
Embarcadero
Login Register

Login

Lost Password

Register

Lost Password