0

Sorry if my question sounds s..., I am new to matplotlib. I have a simple dataset in pandas dataFrame, looks like this:

     TAG_1      TAG_2        testTime
0           5      10, 10         758.2
1           5       16, 4        1738.1
2           5        4, 3         752.2
3           5        5, 3         868.9
4           5        5, 4         742.3

Is there a way I can 3D plot such a data with matplotlib? TAG_1 and TAG_2 are just simple tags, their values are not important at all, So practically I would use just index column 2 times as X axis and Y axis and testTime column as Z axis. Could you provide me a sample code? thank you in advance.

This is the type of plot I am looking for. Sample chart

EDIT: I have managed to plot the following with @furas answer: enter image description here

1 Answer 1

1

Using this code

data = [ [758.2], [1738.1], [752.2], [868.9], [742.3] ]

import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

df = pd.DataFrame(data)

threedee = plt.figure().gca(projection='3d')
threedee.plot(df.index, df.index, df[0])

plt.show()

I get

enter image description here

It uses index as X and Y and column as Z, but I don't know if it is what you expected.


You need more data to draw something more.

I add more columns

data = [
    [0, 1, 100, 758.2],
    [0, 1, 100, 1738.1],
    [0, 1, 100, 752.2],
    [0, 1, 100, 868.9],
    [0, 1, 100, 742.3],
]

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

df = pd.DataFrame(data)

Y = range(df.shape[0])
X = range(df.shape[1])
X, Y = np.meshgrid(X, Y)

threedee = plt.figure().gca(projection='3d')
threedee.plot_wireframe(Y, X, df)

plt.show()

and I get

enter image description here

If I replace X with Y then I get

enter image description here

To get first version you can replace X with Y or transform DataFrame

df = df.T
Sign up to request clarification or add additional context in comments.

6 Comments

Wel thank you so much for the feedback, it works, but what I need is something similar to the image I posted as a sample, is it even possible to have such a chart with matplotlib?
you would need more columns with data - with one column you can draw only one line.
but index values are data, don't they? imagine my data for x-axis is actually 1,2,3,4,5...and the same is true for the y-axis. So I have 3 column now, what then?
X is 1...5 and Y is 1...5 so you have 25 places - so Z need 25 values - 5 columns with 5 values.
Now I see your point, let me check maybe I could reshape the data, thank you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.