Код: Выделить всё
import pandas as pd
import altair as alt
# extract data into a nested list
data = {
"Name of District": ["Kollam", "Beed", "Kalahandi", "West Medinipur", "Birbhum", "Howrah"],
"No. of Cases": [19, 11, 42, 145, 199, 85],
}
# create a dataframe from the extracted data
df = pd.DataFrame(
data
)
# Display the first 5 rows
print(df.head().to_markdown(index=False, numalign="left", stralign="left"))
# Create a bar chart with `Name of District` on the x-axis and `No. of Cases` on the y-axis
chart = alt.Chart(df).mark_bar().encode(
x='Name of District',
y='No. of Cases',
tooltip=['Name of District', 'No. of Cases']
).properties(
title='Bar Chart of No. of Cases by Name of District'
).interactive()
# Save the chart
chart.save('no_of_cases_by_name_of_district_bar_chart.json')
display(chart)
Если я построю график с помощью matplotlib, то получу правильный график:
Я пробовал это в Colab и на своем локальном компьютере, и я получил одинаковые результаты, почему это могло случилось?
Подробнее здесь: https://stackoverflow.com/questions/786 ... ualization