I am creating a joyplot using joypy.
All my data is between[0,1].
But I get a big range of negative values in the graph:
import joypy
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import cm
import matplotlib.ticker as ticker
import matplotlib
matplotlib.use('TkAgg')
iris = pd.read_csv("1_5.csv")
fig, axes = joypy.joyplot(iris)
x = [0,0.25,0.5,0.75,1]
plt.xticks(x)
plt.show()
It isn't clear that your xticks are in any way tied to the actual joyplot itself (ie, you've created arbitrary x-ticks and placed them on the plot).
Are tick marks not represented on the plot originally (similar plots I've seen all have them by default)?
Related
I want to create ridgelines plots for the distribution of property Rg as it changes with temperature. It turns out that I have an attribute Z that changes too, so I want the distribution of Rg at a given condition, for both attributes Z1 and Z2. I want the ridgeline plots to be side by side.
This is what I have so far:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import joypy as j
from joypy import joyplot
import seaborn as sns
df_iso = pd.DataFrame(data=d_iso)
df_atac = pd.DataFrame(data=d_atac)
plt.figure()
joyplot(data=df_iso[['temperature', 'Rg']], by='temperature', column='Rg', figsize=(12, 8))
joyplot(data=df_atac[['temperature', 'Rg']], by='temperature', column='Rg', figsize=(12, 8))
plt.title('Ridgeline plot of Rg histograms')
plt.show()
My plots look like this:
I want them to be on the same plot, with different colors and legends for each color.
How can I go about this? Any advice you have would be appreciated.
The code below takes a dataframe filters by a string in a column and then plot the values of another column
I plot the values of the using histogram and than worked fine until I added Mean, Median and standard deviation but now I am just getting an empty graph where instead the all of the variables mentioned below should be plotted in one graph together with their labels
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
from matplotlib import pyplot as plt
import numpy as np
df = pd.read_csv(r'C:/Users/output.csv', delimiter=";", encoding='unicode_escape')
df['Plot_column'] = df['Plot_column'].str.split(',').str[0]
df['Plot_column'] = df['Plot_column'].astype('int64', copy=False)
X=df[df['goal_colum']=='start running']['Plot_column'].values
dev_x= X
mean_=np.mean(dev_x)
median_=np.median(dev_x)
standard_=np.std(dev_x)
plt.hist(dev_x, bins=5)
plt.plot(mean_, label='Mean')
plt.plot(median_, label='Median')
plt.plot(standard_, label='Std Deviation')
plt.title('Data')
https://matplotlib.org/3.1.1/gallery/statistics/histogram_features.html
There are two major ways to plot in matplotlib, pyplot (the easy way) and ax (the hard way). Ax lets you customize your plot more and you should work to move towards that. Try something like the following
num_bins = 50
fig, ax = plt.subplots()
# the histogram of the data
n, bins, patches = ax.hist(dev_x, num_bins, density=1)
ax.plot(np.mean(dev_x))
ax.plot(np.median(dev_x))
ax.plot(np.std(dev_x))
# Tweak spacing to prevent clipping of ylabel
fig.tight_layout()
plt.show()
If I use the following code I end up with an overcrowded x-axis. I would like to show only every 10th number on the x axis. Meaning [0,10,...].
Any idea how to do this?
import pandas as pd
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
a = pd.DataFrame({'y':np.random.randn(100)})
a['time']=a.index
ax = sns.pointplot(x='time', y="y", data=a)
plt.show()
You may decide not to use a pointplot at all. A usual lineplot seems to suffice.
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
a = pd.DataFrame({'y':np.random.randn(100)})
plt.plot(a.index, a.y)
plt.show()
Now this gives ticks at steps of 20. The easiest option here would be to use
plt.xticks(range(0,101,10))
to get the steps of 10. Or equally possible,
plt.gca().locator_params(nbins=11)
to devide the axis into 11 bins.
Of course the use of an appropriate locator would be equally possible.
i am having some trouble with a seaborn pointplot.
I am to plot the Temperature vs. growth rate of four kinds of bacteria, so that each type has its own graph, but all four are in the same plot. The thing is, i cannot connect the individual points, i can only get the individual points.
My code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats, integrate
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
dataSorted=data.sort_values(['Temperature','Growth_rate'],ascending=[True,True])
plt.subplots()
ax2=sns.pointplot(x='Temperature',y='Growth_rate', hue='Bacteria' ,data=dataSorted,scale=0.7,join=True)
axes2=ax2.axes
axes2.set_xlim(10,60)
axes2.set_ylim(0,1.5)
axes2.set_xticks(np.arange(1,7)*10)
axes2.set_xticklabels(np.arange(1,7)*10)
The output is exactly as specified, apart from the lines between points:
My plot - without lines
I have no idea how to fix this, i have even set the "join" parameter manually, even though it is set as True by default.
Basically, I'm doing scalability analysis, so I'm working with numbers like 2,4,8,16,32... etc and the only way graphs look rational is using a log scale.
But instead of the usual 10^1, 10^2, etc labelling, I want to have these datapoints (2,4,8...) indicated on the axes
Any ideas?
There's more than one way to do it, depending on how flexible/fancy you want to be.
The simplest way is just to do something like this:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
x = np.exp2(np.arange(10))
plt.semilogy(x)
plt.yticks(x, x)
# Turn y-axis minor ticks off
plt.gca().yaxis.set_minor_locator(mpl.ticker.NullLocator())
plt.show()
If you want to do it in a more flexible manner, then perhaps you might use something like this:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
x = np.exp2(np.arange(10))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.semilogy(x)
ax.yaxis.get_major_locator().base(2)
ax.yaxis.get_minor_locator().base(2)
# This will place 1 minor tick halfway (in linear space) between major ticks
# (in general, use np.linspace(1, 2.0001, numticks-2))
ax.yaxis.get_minor_locator().subs([1.5])
ax.yaxis.get_major_formatter().base(2)
plt.show()
Or something like this:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
x = np.exp2(np.arange(10))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.semilogy(x)
ax.yaxis.get_major_locator().base(2)
ax.yaxis.get_minor_locator().base(2)
ax.yaxis.get_minor_locator().subs([1.5])
# This is the only difference from the last snippet, uses "regular" numbers.
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
plt.show()