# libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
import sys
# open CSV file
file = pd.read_csv("abc.csv")
print (file.head())
print("press 2 for two columns ")
print("press 3 for three columns ")
# for 3d plotting
def scatter3D(head1,head2,head3):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x=list(head1)
y=list(head2)
z=list(head3)
ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
plt.savefig("scatter3D.png")
plt.show()
def bar3D(head1,head2,head3):
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
xpos = head1
ypos = head2
x=len(xpos)
y=len(ypos)
zpos = np.zeros(x)
dx = np.ones(x)
dy = np.ones(y)
dz = head3
ax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color='#00ceaa')
ax1.set_xlabel('X Label')
ax1.set_ylabel('Y Label')
ax1.set_zlabel('Z Label')
plt.savefig("bar3D.png")
plt.show()
def threecolmuns():
new = input("enter ist column ")
new2 =input("enter second column ")
new3 =input("enter third column ")
head1 = np.array(file[new])
head2 = np.array(file[new2])
head3 = np.array(file[new3])
print("chose your plot\n")
print("Press 11 for scatter3D plot")
print("Press 22 for bar3D plot")
print("Press 0 to quit")
print("For switching to 2D plots press 9 ")
while True:
choice11=int(input())
if choice11==11:
scatter3D(head1,head2,head3)
elif choice11==22:
bar3D(head1,head2,head3)
elif choice11==9:
twocolumns()
elif choice11==0:
sys.exit(0)
# for 2d plotting
def linear(head1,head2):
plt.plot(head1,head2,label= 'drugs')
plt.ylabel("y axix")
plt.xlabel("x axix")
plt.title("liner plot")
plt.savefig('liner.png')
plt.show()
def scatter(head1,head2):
sns.scatterplot(head1,head2,label= 'drugs')
plt.ylabel("y axix")
plt.xlabel("x axix")
plt.title("scatter plot")
plt.savefig('scatter.png')
plt.show()
def bar(head1,head2):
sns.barplot(head1,head2,palette ='hls',label= 'drugs')
plt.ylabel("y axix")
plt.xlabel("x axix")
plt.title("bar plot")
plt.savefig('bar.png')
plt.show()
def histogram(head1,bins=10):
sns.set()
plt.hist(head1,bins=10,label= 'drugs')
plt.ylabel("y axix")
plt.xlabel("x axix")
plt.title("historam")
plt.savefig('hist.png')
plt.show()
def twocolumns():
global new
global new2
new = input("enter ist column ")
new2 =input("enter second column ")
head1 = np.array(file[new])
head2 = np.array(file[new2])
print("\n")
print("chose your Graph\n")
print("Press 1 for linear plot")
print("Press 2 for Scattor plot")
print("Press 3 for Bar plot")
print("Press 4 for Histogram")
print("Press 5 to get all plots")
print("For switching to 3D plots press 9 ")
print("Press 0 to exit\n")
while True:
choice =int(input())
if choice== 1:
linear(head1,head2)
elif choice== 2:
scatter(head1,head2)
elif choice== 3:
bar(head1,head2)
elif choice== 4:
histogram(head1,bins=10)
elif choice==5:
histogram(head1,bins=10)
bar(head1,head2)
linear(head1,head2)
scatter(head1,head2)
elif choice==9:
threecolmuns()
elif choice==0:
sys.exit(0)
while True:
choice = int (input())
if choice==2:
twocolumns()
elif choice==3:
threecolmuns()
0 Comments