Plotly
Plotly
Python Code
import plotly.express as px
import pandas as pd
# Graph functions
def generate_all_charts(template):
print(f"Generating charts with template: {template}")
# Line Chart
fig_line = px.line(df, x=x_column, y=y_column, title=f"Line Chart -
{template}", template=template)
fig_line.show()
# Bar Chart
fig_bar = px.bar(df, x=x_column, y=y_column, title=f"Bar Chart -
{template}", template=template)
fig_bar.show()
# Scatter Plot
fig_scatter = px.scatter(df, x=x_column, y=y_column,
color=category_column, title=f"Scatter Plot - {template}", template=template)
fig_scatter.show()
# Pie Chart
if category_column in df.columns:
fig_pie = px.pie(df, names=category_column, title=f"Pie Chart -
{template}", template=template)
fig_pie.show()
# Histogram
fig_hist = px.histogram(df, x=x_column, title=f"Histogram - {template}",
template=template)
fig_hist.show()
# Box Plot
fig_box = px.box(df, x=category_column, y=y_column, title=f"Box Plot -
{template}", template=template)
fig_box.show()
# Loop through all templates and generate charts
for template in templates:
generate_all_charts(template)
1. Graphs Covered:
o Line Chart
o Bar Chart
o Scatter Plot
o Pie Chart
o Histogram
o Box Plot
2. Templates Applied: Loops through all Plotly templates like:
o 'plotly'
o 'plotly_dark'
o 'ggplot2'
o 'seaborn'
o 'simple_white'
o 'none'
3. Customizable Columns: Replace the placeholders (x_column, y_column,
category_column) with actual column names from your CSV file.
4. Display Each Chart: Each chart is displayed using .show() with the current template
applied.
Notes:
If your CSV doesn't have a column suitable for category_column (like categories or
groups), you can skip Pie Chart and Box Plot by commenting out the respective code.
Ensure your CSV has numeric data for the y_column to support charts like Line, Bar, etc.
You can save the visualizations as HTML or PNG using
fig.write_html("filename.html") or fig.write_image("filename.png").