How can I make a 3D line plot?

2024/11/18 17:27:26

I want to generate the lines, which I get from an array in 3D.

Here is the code:

VecStart_x = [0,1,3,5]
VecStart_y = [2,2,5,5]
VecStart_z = [0,1,1,5]
VecEnd_x = [1,2,-1,6]
VecEnd_y = [3,1,-2,7]
VecEnd_z  =[1,0,4,9]import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')ax.plot([VecStart_x ,VecEnd_x],[VecStart_y,VecEnd_y],[VecStart_z,VecEnd_z])
plt.show()
Axes3D.plot()

I get that error:

ValueError: third arg must be a format string

Answer

I guess, you want to plot 4 lines. Then you can try

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')for i in range(4):ax.plot([VecStart_x[i], VecEnd_x[i]], [VecStart_y[i],VecEnd_y[i]],zs=[VecStart_z[i],VecEnd_z[i]])

As Nicolas has suggested, do have a look at the matplotlib gallery.

enter image description here

https://en.xdnf.cn/q/26533.html

Related Q&A

Cut multiple parts of a video with ffmpeg

In what Im trying to do, I need to remove some parts of a video file, and create a new one from that.For example, from a video file like this:===================I make two cuts======||=====||||==and ge…

Can I fake/mock the type of my mock objects in python unittests

In my python code I check the type of one of the parameters to make sure it is of the type I expect. For instance: def myfunction(dbConnection):if (type(dbConnection)<>bpgsql.Connection):r[error…

Changing the background color of the axes planes of a 3D plot

On the basis of the scatterplot example of matplotlib, how can I change the gray background color of the 3 axes grid planes? I would like to set it to white, keeping the grid lines with the default gr…

Select checkbox using Selenium with Python

How can I select the checkbox using Selenium with Python? from selenium import webdriver from selenium.webdriver.common.keys import Keysbrowser = webdriver.Firefox() url = Any URL browser.get(url)brow…

linear programming in python?

I need to make a linear programming model. Here are the inequalities Im using (for example):6x + 4y <= 24 x + 2y <= 6 -x + y <= 1 y <= 2I need to find the area described by these inequaliti…

Beginner Python Practice? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic…

Pylint: Disable specific warnings for specific folder

We have a Python project laid out like this:project/ ├── .pylintrc ├── module1.py ├── module2.py └── tests/├── test_module1.py└── test_module2.pyOur unit and function tests reside in …

PyCharm: Configuring multi-hop remote Interpreters via SSH

To connect to the computer at my office I need to run ssh twice. First to connect to the host-1 and then from host-1 to host-2 and each one has different credentials. However the configuration menu in …

Return results from multiple models with Django REST Framework

I have three models — articles, authors and tweets. Im ultimately needing to use Django REST Framework to construct a feed that aggregates all the objects using the Article and Tweet models into one r…

Comparing XML in a unit test in Python

I have an object that can build itself from an XML string, and write itself out to an XML string. Id like to write a unit test to test round tripping through XML, but Im having trouble comparing the tw…