Draw a flat surface with a matplotlib 3d graph

If you read the tutorials on matplot, you can find many nice examples of 3d drawing such as saddle type and trigonometric function composition. In practice, for example, you want to plot the number of customers, sales (depending on the number of customers), and time (independent variable) to show when the number of customers and sales exceeded or fell below the threshold. There are times when Z does not depend on X or Y and you simply want to stretch y = f (x) in the Z direction for display. I thought it would be easy, but I was worried because there were few examples because it was too plain in the picture, so I would like to make a note of it. I have a very short history of programming, so if you have any suggestions for improvement, please do not hesitate to contact me.

python


import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

x = [1,2,3,4,5]
y = [2,4,6,8,10]
z = np.linspace(0,100,11)
Y,Z = np.meshgrid(y,z)
X = np.array([x]*Y.shape[0])

fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.plot_surface(X,Y,Z,alpha = 0.3) 

2.png

python


x = 2
y = np.linspace(0,100,11)
z = np.linspace(0,100,11)
Y,Z = np.meshgrid(y,z)
X = np.array([x]*Y.shape[0])

fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.plot_surface(X,Y,Z,alpha=0.3)

5.png

After that, you can overlay the 3D scatter plot or draw the wire frame line from above. However, the 3D drawing on the display is hard to see from the side that can be seen, so I think it is better not to use it as much as possible.

Recommended Posts

Draw a flat surface with a matplotlib 3d graph
Draw a loose graph with matplotlib
Draw a "breast curved surface" in a 3D graph (1)
Draw a graph with matplotlib from a csv file
Draw a "breast curved surface" in a 3D graph (2)
Draw a graph with NetworkX
Draw a graph with networkx
[Python] How to draw a line graph with Matplotlib
Draw a graph with Julia + PyQtGraph (2)
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a graph with PySimple GUI
Study math with Python: Draw a sympy (scipy) graph with matplotlib
How to draw a graph using Matplotlib
Draw a graph with PyQtGraph Part 1-Drawing
Create a graph with borders removed with matplotlib
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
How to draw a 3D graph before optimization
[Python] limit axis of 3D graph with Matplotlib
(Matplotlib) I want to draw a graph with a size specified in pixels
Draw a graph with PyQtGraph Part 3-PlotWidget settings
Draw a graph by processing with Pandas groupby
[Python] Draw a directed graph with Dash Cytoscape
How to draw a bar graph that summarizes multiple series with matplotlib
Band graph with matplotlib
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with PyQtGraph Part 6-Displaying a legend
3D plot with matplotlib
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
Forcibly draw something like a flowchart with Python, matplotlib
[Python] How to create a 2D histogram with Matplotlib
Draw a graph with PyQtGraph Part 2--Detailed plot settings
[Python] How to draw a scatter plot with Matplotlib
Graph Excel data with matplotlib (1)
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
[Visualization] I want to draw a beautiful graph with Plotly
A python graphing manual with Matplotlib.
Solve ABC166 A ~ D with Python
Draw Japanese with matplotlib on Ubuntu
Draw a beautiful circle with numpy
Draw retention rate graph in Matplotlib
Let's make a graph with python! !!
Easy to draw graphs with matplotlib
Make a nice graph with plotly
Draw Lyapunov Fractal with Python, matplotlib
Write a stacked histogram with matplotlib
Easily draw a map with matplotlib.basemap
[Python] Set the graph range with matplotlib
[PyQt] Display a multi-axis graph with QtChart
Try drawing a normal distribution with matplotlib
Draw a heart in Ruby with PyCall
Make a partially zoomed figure with matplotlib
Draw a Mandelbrot set with Brainf * ck
Draw a graph that can be moved around with HoloViews and Bokeh
Draw hierarchical axis labels with matplotlib + pandas
Solve AtCoder ABC168 with python (A ~ D)
Graph trigonometric functions with numpy and matplotlib