Every time I draw a graph with python, I check it, so I will summarize only the simplest usage

Every time I draw a graph with python, I check it, so I will summarize only the simplest usage

I'm using jupyter notebook. If it's not a jupyter notebook, you don't need "% matplotlib inline"

2D graph


#Library import
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

#Function you want to draw a graph
def func(x):
    return x**2

#Variable preparation
# np.arange(start,End,Step)
x = np.arange(0.0, 10.0, 0.1)
y = func(x)

#Draw on graph
plt.plot(x, y);

2d.png

3D graph


#Library import
%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

#Function you want to draw a graph
def func(x, y):
    return x * y * (10 - x - y)

#Variable preparation
x = np.arange(0.0, 10.0, 0.1)
y = np.arange(0.0, 10.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = func(X, Y)

#drawing
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("f(x, y)")
ax.plot_wireframe(X, Y, Z)
plt.show()

3d.png

Recommended Posts

Every time I draw a graph with python, I check it, so I will summarize only the simplest usage
I made a segment tree with python, so I will introduce it
I customized it with Visual Studio Code (mainly for python), so I will summarize it
I tried using "Asciichart Py" which can draw a beautiful graph on the console with Python.
I researched Docker, so I will summarize it
I tried to make a calculator with Tkinter so I will write it
[Streamlit] I hate JavaScript, so I make a web application only with Python
[Python] Draw a directed graph with Dash Cytoscape
I was able to mock AWS-Batch with python, moto, so I will leave it
When I made a treemap (area graph) with python, it was subtle, so when I used flourish, it felt pretty good.
I use python but I don't know the class well, so I will do a tutorial
I have read a survey paper on time-series anomaly detection, so I will summarize it.
A Python beginner made a chat bot, so I tried to summarize how to make it.
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
[Python] How to draw a line graph with Matplotlib
I tried to draw a route map with Python
A memo that I touched the Datastore with python
I want to cut out only the face from a person image with Python and save it ~ Face detection and trimming with face_recognition ~
I made a function to crop the image of python openCV, so please use it.
I replaced the Windows PowerShell cookbook with a python script.
Study math with Python: Draw a sympy (scipy) graph with matplotlib
I made a package to filter time series with python
[Visualization] I want to draw a beautiful graph with Plotly
Draw a graph with NetworkX
Draw a graph with networkx
GCP's Cloud Shell Editor was clogged up with the Python development environment, so I managed to rebuild it in a vacant lot.
QR code creation with Python. I don't want to line up because I write the same thing every time I issue a commuter pass. ..
Check server I / O device usage with the Linux iostat command
I wanted to solve the ABC164 A ~ D problem with Python
[Super basics of Python] I learned the basics of the basics, so I summarized it briefly.
Homework was a pain, so I do management accounting with Python
I made a chatbot with Tensor2Tensor and this time it worked
I ran GhostScript with python, split the PDF into pages, and converted it to a JPEG image.
Draw a graph with Julia + PyQtGraph (2)
Since the organization called Cabinet Secretariat has released data in a format other than JSON even though it is written as JSON, I will summarize how to save JSON format data with python
Draw a loose graph with matplotlib
I made a fortune with Python.
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
I liked the tweet with python. ..
Draw a graph with pandas + XlsxWriter
Let's make a graph with python! !!
Draw a graph with PySimple GUI
I made a daemon with Python
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
I set the environment variable with Docker and displayed it in Python
I tried using "Streamlit" which can do the Web only with Python
I get a Python No module named'encodings' error with the aws command
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
[Python, ObsPy] I drew a beach ball on the map with Cartopy + ObsPy.
I made a GAN with Keras, so I made a video of the learning process.
For the first time in Numpy, I will update it from time to time
I made a program to check the size of a file in Python
Python: I want to measure the processing time of a function neatly
I wanted to use the find module of Ansible2, but it took some time, so make a note
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
I wanted to know the number of lines in multiple files, so I tried to get it with a command