Lab Py
Lab Py
BAR PLOT
1B.SCATTER PLOT
2B.PYE CHART
# Generate x values
x = np.linspace(-10, 10, 100)
# Calculate y values
y = m * x + b
# Add legend
plt.legend()
# Plot sin(x)
axs[0].plot(x, y1, color="blue", label='y = sin(x)')
axs[0].set_title('Sin Function')
axs[0].set_ylabel('sin(x)')
axs[0].grid(True)
axs[0].legend()
# Plot cos(x)
axs[1].plot(x, y2, color='orange', label='y = cos(x)')
axs[1].set_title('Cosine Function')
axs[1].set_ylabel('cos(x)')
axs[1].grid(True)
axs[1].legend()
# Plot tan(x)
axs[2].plot(x, y3, color='green', label='y = tan(x)')
axs[2].set_title('Tan Function')
axs[2].set_ylim(-10, 10) # Limit the y-axis for better visualization
axs[2].grid(True)
axs[2].legend()
6.3D
import plotly.graph_objects as go
from plotly.offline import plot
students_data={
'Name':['Anil','Sunil','Kumar','Rajesh'],
'Height':[160,155,170,165],
'Weight':[55,50,65,60],
'Age':[20,19,21,20]
}
hover_text=[('Name:{name}<br> Height:{height}<br>Weight:{weight}<br>Age:{agre}'
for name,height,weight,age in zip(students_data['Name'],
students_data['Height'],students_data['Weight'],students_data['Age'] ))]
fig=go.Figure(data=[go.Scatter3d(
x=students_data['Height'],
y=students_data['Weight'],
z=students_data['Age'],
mode='markers',
marker=dict(size=10,color="blue",opacity=0.8),text=hover_text)])
fig.update_layout(scene=dict(xaxis_title='Height',yaxis_title='Weight',
zaxis_title='Age'),title='3D scatter plot of students Data')
plot(fig,filename='student_plot.html')
7A.TIME SERIES
import plotly.express as px
import pandas as pd
from plotly.offline import plot
# Create DataFrame
df = pd.DataFrame(data)