I would like to have every column on my x-Axis and every value on my y-Axis.
With plotly and seaborn I could only find a way to plot the values against each other (column 1 on x vs coulmn 2 on y).
So for my shown example following would be columns:
"Import Files", "Defining Variables", "Simulate Cutting Down",...
I would like to have all theri values on the y-Axis.
So what I basically want is
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('timings.csv')
df.T.plot()
plt.show()
but with scatter. Matplotlib, Seaborn or Plotly is fine by me.
This would be an example for a csv File, since I can't upload a file:
Import Files,Defining Variables,Copy All Cutters,Simulate Cutting Down,Calculalte Circle, Simulate Cutting Circle, Calculate Unbalance,Write to CSV,Total Time
0.015956878662109375,0.0009989738464355469,0.022938966751098633,0.1466083526611328,0.0009968280792236328,48.128061294555664,0.0,0.014995098114013672,48.33055639266968
0.015958786010742188,0.0,0.024958133697509766,0.14598894119262695,0.0,49.22848296165466,0.0,0.004987239837646484,49.42037606239319
0.015943288803100586,0.0,0.036900997161865234,0.14561033248901367,0.0,46.80884146690369,0.0,0.004009723663330078,47.011305809020996
I only used the data you provided; as mentioned by others in the comments, barplot is more suited for this data but here it is with scatter plot:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(16,5))
sns.scatterplot(data=df.melt(), x='variable', y ='value', ax=ax)
ax.set_xlabel('')
ax.set_ylabel('Time in seconds')
Related
suppose I am plotting scatter plot in seaborn python
import seaborn as sns
df = sns.load_dataset("penguins")
sns.scatterplot(data=df, x="flipper_length_mm", y="body_mass_g",hue="sex",s=300)
What I want is boundary lines of max and min values in each scale.
The question might be hard to understand. If you didn't understand you can tell me
You'll need to calculate your min and max values for each axis. You can use the panda DataFrame methods .min() and .max() for that respectively.
To add them as lines to your scatterplot you can use the matplotlib.pyplot methods, .axhline() and .axvline() for your horizontal/y-axis and vertical/x-axis.
For example adding a horizontal min line:
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset("penguins")
graph = sns.scatterplot(data=df, x="flipper_length_mm", y="body_mass_g",hue="sex",s=300)
graph.axhline(df['body_mass_g'].min())
I tried to generate 2 plots using seaborn and the 2nd plot i got seemed to be overlaying the first plot
Here's the code
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
sns.pairplot(iris)
plt.savefig("Pairplot")
sns.heatmap(iris.corr())
plt.savefig("heatmap")
Output
1st plot
2nd plot
You could create a new figure prior to plotting the heatmap:
plt.figure()
sns.heatmap(iris.corr())
I only just stepped into Python and I'm trying to generate a scatter plot with several categories. I am using the Iris Dataset as a basis, here is what I have so far:
import matplotlib.pyplot as plt
import numpy as np
fig,ax = plt.subplots(1)
iris_data = np.genfromtxt(
"iris.csv", names=True,
dtype="float", delimiter=",")
x=iris_data["sepal_length"]
y=iris_data["sepal_width"]
g=iris_data["class"]
plt.scatter(x,y)
plt.show()
I don't know how to separate out the classes and plot each one on the same graph.
I am coming from Matlab where all I needed was the
"gscatter(x,y,g) creates a scatter plot of x and y, grouped by g" to get the job done, but I am finding out that python needs a little more to get the group by g part done.
Thank you in advance for any help.
Use seaborn:
import seaborn as sns, matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
sns.scatterplot(x='sepal_length',y='sepal_width',data=iris,hue='species')
plt.show()
Result:
You can do the same in matplotlib as in the example below as long as your data is organized in a pandas DataFrame:
for k,g in iris.groupby('species'):
plt.scatter(g['sepal_length'],g['sepal_width'],label=k)
I am using pandas scatter_matrix (couldn't get PairgGrid in seaborn to work) to plot all combinations of a set of columns in a pandas frame. Each column as 1000 data points and there are nine columns.
I am using the following code:
pandas.plotting.scatter_matrix(df, alpha=0.2, figsize=(8,8))
I get the figure shown below:
This is nice., However, you'll notice that across the main diagonal I have a mirror image. Is it possible to plot only the lower portion as in the following fake plot I made using paint:
This is probably not the cleanest way to do it, but it works:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
axes = pd.plotting.scatter_matrix(iris, alpha=0.2, figsize=(8,8))
for i in range(np.shape(axes)[0]):
for j in range(np.shape(axes)[1]):
if i < j:
axes[i,j].set_visible(False)
I am trying to plot two Pandas Series with matching indexes on the same plot (one as a line and the other as bars) using the df.plot() syntax. But when I add the bar plot the line plot axis ends up wrong. Why isn't this working?
import pandas as pd
import matplotlib.pyplot as plt
plt.figure()
df = pd.Series({0.142:5,0.3643:1,0.5523:2})
df.plot(use_index=True)
df.plot(kind='bar',secondary_y=True,color='b',use_index=True)