[LINUX] Draw graphs in Julia ... Leave the graphs to Python

"Draw a graph in the programming language Julia" I succeeded in moving the sample for the time being, but the data created by my own program (in Julia language) I decided to find out how to draw a graph using. Well, I wanted to use 3D graphs (OpenGL), and I thought it would be difficult to port all the sample code of PyQtGraph to Julia. ** Okay, change policy ... Let's leave all the graphs to Python! ** **

As a result, it became the source code at the end of the sentence.

test3.gif

By leaving the processing of graphs ** to the Python code **, development has become super easy! After that, if there is a sample that performs such calculation processing on the Julia side ... ** Next, let's try a 3D graph using OpenGL! ** **

Note: Please refer to "Drawing a graph in the programming language Julia" for environment construction.

text:Plotting.jl(C:\julia-0.2.1-win32\Save to bin)


using PyCall

@pyimport Plotting
Plotting.my_graph_set([1, 2, 3, 4, 5, 10, 20, 5])
Plotting.my_graph_run()

python:Plotting.py(C:\julia-0.2.1-win32\Save to bin)


# -*- coding: utf-8 -*-
"""
This example demonstrates many of the 2D plotting capabilities
in pyqtgraph. All of the plots may be panned/scaled by dragging with 
the left/right mouse buttons. Right click on any plot to show a context menu.
"""

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg

plot_data_1 = []

def my_graph_set(plot_data):
	global plot_data_1
	plot_data_1 = plot_data

def my_graph_run():
	global plot_data_1

	app = QtGui.QApplication([])

	win = pg.GraphicsWindow(title="Basic plotting examples")
	win.resize(800,600)
	win.setWindowTitle('pyqtgraph example: Plotting')

	# Enable antialiasing for prettier plots
	pg.setConfigOptions(antialias=True)

	p1 = win.addPlot(title="Basic array plotting", y=plot_data_1)

	p2 = win.addPlot(title="Multiple curves")
	p2.plot(np.random.normal(size=100), pen=(255,0,0))
	p2.plot(np.random.normal(size=100)+5, pen=(0,255,0))
	p2.plot(np.random.normal(size=100)+10, pen=(0,0,255))

	p3 = win.addPlot(title="Drawing with points")
	p3.plot(np.random.normal(size=100), pen=(200,200,200), symbolBrush=(255,0,0), symbolPen='w')

	win.nextRow()

	p4 = win.addPlot(title="Parametric, grid enabled")
	x = np.cos(np.linspace(0, 2*np.pi, 1000))
	y = np.sin(np.linspace(0, 4*np.pi, 1000))
	p4.plot(x, y)
	p4.showGrid(x=True, y=True)

	p5 = win.addPlot(title="Scatter plot, axis labels, log scale")
	x = np.random.normal(size=1000) * 1e-5
	y = x*1000 + 0.005 * np.random.normal(size=1000)
	y -= y.min()-1.0
	mask = x > 1e-15
	x = x[mask]
	y = y[mask]
	p5.plot(x, y, pen=None, symbol='t', symbolPen=None, symbolSize=10, symbolBrush=(100, 100, 255, 50))
	p5.setLabel('left', "Y Axis", units='A')
	p5.setLabel('bottom', "Y Axis", units='s')
	p5.setLogMode(x=True, y=False)

	global curve, data, ptr, p6
	p6 = win.addPlot(title="Updating plot")
	curve = p6.plot(pen='y')
	data = np.random.normal(size=(10,1000))
	ptr = 0
	def update():
		global curve, data, ptr, p6
		curve.setData(data[ptr%10])
		if ptr == 0:
			p6.enableAutoRange('xy', False)  ## stop auto-scaling after the first data set is plotted
		ptr += 1
	timer = QtCore.QTimer()
	timer.timeout.connect(update)
	timer.start(50)

	win.nextRow()

	p7 = win.addPlot(title="Filled plot, axis disabled")
	y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)
	p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))
	p7.showAxis('bottom', False)

	x2 = np.linspace(-100, 100, 1000)
	data2 = np.sin(x2) / x2
	p8 = win.addPlot(title="Region Selection")
	p8.plot(data2, pen=(255,255,255,200))
	lr = pg.LinearRegionItem([400,700])
	lr.setZValue(-10)
	p8.addItem(lr)

	p9 = win.addPlot(title="Zoom on selected region")
	p9.plot(data2)
	def updatePlot():
	    p9.setXRange(*lr.getRegion(), padding=0)
	def updateRegion():
	    lr.setRegion(p9.getViewBox().viewRange()[0])
	lr.sigRegionChanged.connect(updatePlot)
	p9.sigXRangeChanged.connect(updateRegion)
	updatePlot()

	QtGui.QApplication.instance().exec_()

Recommended Posts

Draw graphs in Julia ... Leave the graphs to Python
Draw graphs in the programming language Julia
Leave the troublesome processing to Python
In the python command python points to python3.8
Output "Draw ferns programmatically" to the drawing process in Python
How to use the C library in Python
[Python] How to draw multiple graphs with Matplotlib
To dynamically replace the next method in python
The trick to write flatten concisely in python
How to get the files in the [Python] folder
[Python] How to draw a histogram in Matplotlib
Draw graph in python
I want to display the progress in Python!
I tried to graph the packages installed in Python
How to get the variable name itself in python
How to get the number of digits in Python
How to know the current directory in Python in Blender
Carefully understand the exponential distribution and draw in Python
Convert the image in .zip to PDF with Python
Carefully understand the Poisson distribution and draw in Python
I want to write in Python! (3) Utilize the mock
How to use the model learned in Lobe in Python
[Python] How to output the list values in order
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
I want to use the R dataset in python
Python OpenCV tried to display the image in text.
To flush stdout in Python
Draw mp3 waveform in Python
Download the file in Python
Find the difference in Python
Login to website in Python
Draw "Draw Ferns Programmatically" in Python
Draw implicit function in python
Speech to speech in python [text to speech]
How to develop in Python
Draw a heart in Python
Post to Slack in Python
[python] How to check if the Key exists in the dictionary
How to debug the Python standard library in Visual Studio
[python] How to use the library Matplotlib for drawing graphs
How to use the __call__ method in a Python class
Various ways to calculate the similarity between data in python
How to get the last (last) value in a list in Python
I tried to implement the mail sending function in Python
Draw Sine Waves in Blender Python
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Getting the arXiv API in Python
Convert markdown to PDF in Python
Python in the browser: Brython's recommendation
How to collect images in Python
Hit the Sesami API in Python
Draw knots interactively in Plotly (Python)
Get the desktop path in Python
How to use SQLite in Python
Programming to fight in the world-Chapter 4
Get the script path in Python
Implement the Singleton pattern in Python
How to get the Python version
Try to calculate Trace in Python