import pandas as pd
import tkinter
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sn
data= pd.read_csv(r'C:\Users\AmitSatappa\Desktop\praticalone\netflix_titles.csv',encoding='cp1252')
matplotlib.use('TkAgg')
duplicate= data[data.duplicated()]
data.drop_duplicates(inplace=True)
new_data= data[data.duplicated()]
nullvalue = data.isnull()
plt.ylim(1,3000)
sn.barplot(nullvalue)
plt.show()
[before setting the plt.ylim i was getting the graph but after setting the limit i am geeting it as blank onlyenter image description here](https://i.stack.imgur.com/mPHxz.png)
Related
When rendering matplotlib charts using pyscript and using figure(figsize) the chart disappears and replaces the x and y axes. Why is this happening?
With figsize
Without figsize
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from pyodide.http import open_url
url = open_url('../data/salaries.csv')
df = pd.read_csv(url)
df_no_outliers=df[(df.salary_in_usd>min) & (df.salary_in_usd<max)]
top_jobs=df_no_outliers.job_title.value_counts()[:7]
plt.figure(2)
barplot = sns.barplot(x='work_year', y='salary_in_usd', data=df_no_outliers)
plt.tight_layout()
plt.figure(figsize=(15,8))
plt
Can someone help me with how to create a scatterplot. I have written the following code, however, it is not the scatter plot link that I expected as all data only concentrate 3 values of x-variable
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression
from scipy.stats import skew
from warnings import filterwarnings
filterwarnings('ignore')
df_transactions = pd.read_csv('transactions.csv')
daily_revenue= df_transactions.groupby("days_after_open").sum()['revenue']
df_transactions["daily_revenue"] = daily_revenue
x = df_transactions["days_after_open"]
y = df_transactions["daily_revenue"]
plt.scatter(x,y,alpha=0.2)
plt.xlabel("Days After Open (days)")
plt.ylabel("Daily Reveue ($)")
plt.savefig("plot")
dataframe image
Please define the 'daily_revenue' following before moving to the scatter plot.
y = df_transactions["daily_revenue"]
I'm having trouble creating this plot in spyder:
import seaborn as sns
import pandas as pd
from pandas.api.types import CategoricalDtype
diamonds= sns.load_dataset("diamonds")
df=diamonds.copy()
cut_Kategoriler=["Fair","Good","Very Good","Premium","Ideal"]
df.cut=df.cut.astype(CategoricalDtype(categories = cut_Kategoriler,ordered=True))
print(df.head())
sns.catplot(x="cut",y="price",data=df)
sns.barplot(x="cut",y="price",hue="color",data=df)
I want create two plots. But these plots overflap. How can i separate the graphics in the last two lines?
You need to import matplotlib.pyplot as plt and then add plt.show() after each of the two plots.
The modified code is added below:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt # Import Matplotlib
from pandas.api.types import CategoricalDtype
diamonds = sns.load_dataset("diamonds")
df=diamonds.copy()
cut_Kategoriler=["Fair","Good","Very Good","Premium","Ideal"]
df.cut=df.cut.astype(CategoricalDtype(categories = cut_Kategoriler,ordered=True))
print(df.head())
sns.catplot(x="cut",y="price",data=df)
plt.show() # Display the first plot
sns.barplot(x="cut",y="price",hue="color",data=df)
plt.show() # Display the second plot
So, this is the code, and for some reason, nothing shows up when I call fig? just a blank line, tried it with plot(),show(), still no use.
import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
from plotly.offline import iplot
df = pd.read_csv('covid_19_data.csv')
sns.set(rc={'figure.figsize':(8,8)})
sns.heatmap(df.isnull(),yticklabels=False)
df['ObservationDate'] = pd.to_datetime(df['ObservationDate'],format='%m/%d/%Y',utc=True)
df_grp = df.groupby('ObservationDate').agg({'Confirmed':'sum','Deaths':'sum','Recovered':'sum'})
df_grp['Active'] = df_grp['Confirmed'] -df_grp['Deaths'] - df_grp['Recovered']
df_grp = df_grp.reset_index()
fig = px.bar(df_grp,x ='ObservationDate',y = 'Confirmed',color_discrete_sequence=['red'])
this is the pic of what happens It doesn't come in the plot section as well.
Here for download is the data set under covid_19_data
https://www.kaggle.com/sudalairajkumar/novel-corona-virus-2019-dataset
I am building a seaborn graphics with this code :
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
%matplotlib inline
df=pd.DataFrame(data=['a','b','c','d','a','a','b','c','a','a'],columns['datos'])
tabla=df['datos'].value_counts().reset_index()
fig, ax1 = plt.subplots(figsize=(6,4))
sns.set()
sns.barplot(x='index', y='datos', data=tabla, ax=ax1)
It does work properly....but How could I get the code of the colors used for every bar?
I have tried with :
f.get_color()
ax.get_color()
but no success at all...
thanks in advance
waly
I admit it's an ugly way, but you will need to access the children of your plot. Note that this probably won't work if you plot more than just the countplot, since you will get all used Rectangle colors in your plot.
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import pandas as pd
import seaborn as sns
%matplotlib inline
sns.set()
df=pd.DataFrame(data=['a','b','c','d','a','a','b','c','a','a'],columns=['datos'])
tabla=df['datos'].value_counts().reset_index()
fig, ax1 = plt.subplots(figsize=(6,4))
sns.barplot(x='index', y='datos', data=tabla, ax=ax1)
bars = [r for r in ax1.get_children() if type(r)==Rectangle]
colors = [c.get_facecolor() for c in bars[:-1]] # I think the last Rectangle is the background.