My seaborn heatmap is showing multiple scales (for each column I presume)
Attached an image showing the code, data & chart.
Wondering how I can remove the multiple scales on the right and show only 1.
clustered_heatmap = clustered_points.groupby("Predicted Clusters").sum()
clustered_heatmap = clustered_heatmap.drop(clustered_heatmap.columns[0], axis = 1)
clustered_heatmap
You can try this:
# Create heatmap
plt.figure(figsize=(16,9))
sns.heatmap(clustered_heatmap)
Related
I have a data frame as shown below
I need to plot it's line chart using plotly with X axis a "Supply[V]" and Y axis a all the columns
shown in the blue box.
Below is my code ,but no output is coming.
Vcm_Settle_vs_supply_funct = px.line(df_vcm_set_funct_mode1, x = 'Supply[V]', y = df_vcm_set_funct_mode1.columns[5:-9])
Vcm_Settle_vs_supply_funct.show()
But no output is coming may I know where I went wrong
Is the column designation correct? I created a code with the data you presented. It just looks like two lines because the data is almost two different types. I have changed the graph size and added a scale range detail for the y-axis.
import plotly.express as px
fig = px.line(df,x='Supply[V]', y=['VCM_10ms','VCM_20ms','VCM_5s','VCM_DEL1A_10ms','VCNI_DELIA_20ms'])
fig.update_yaxes(tickvals=np.arange(-0.1, 1.5, 0.05))
fig.update_layout(height=600)
fig.show()
I am trying to plot a simple boxplot for a large dataset(more than one million records) that I converted from pyspark to pandas to perform some preliminary data analysis. The problem is that when I try to visualize one of the feature with a boxplot the y axis does not reflect the real values(or at least it rescale everything I think).
# Describe basic statistics for the features (1)
DF.select('#followers', '#friends', '#favorites').describe().show()
df_pandas = DF.toPandas()
fig = plt.figure(figsize =(10, 7))
# Creating plot
plt.boxplot(df_pandas["#followers"])
# show plot
plt.show()
I have a simple facet_wrap barplot generated in python plotly that looks like the attached image.
Is it possible to order the x-axis to another facet than the last one. The pandas dataframe is sorted according to the y-axis (which is what I want) but would like this specifically on second-to-last facet (so that it looks similar to the last one in the current plot) but keep the current order of the facet. simple facet_wrap barplot
Sample code below. This will automatically sort the x-axis according to the bottom facet - which is "DEN_Tumour_WD" in this case.
toPlot = pd.DataFrame(allModel)
toPlot = toPlot.sort_values(by=['Flux Ratio (log-scaled)'])
fig = px.bar(toPlot,
x='Reaction',
y='Flux Ratio (log-scaled)',
template = 'none',
facet_row="Model",
color='Subsystem',
category_orders={"Model": ["nonDEN_Liver_CD",
"nonDEN_Liver_WD",
"DEN_Liver_CD",
"DEN_AdjLiver_WD",
"DEN_Tumour_WD"]})
Using matlotlib, I can create figures that look like this:
Here, each row consists of a series of numbers from 0 to 0.6. The left hand axis text indicates the maximum value in each row. The bottom axis text represents the column indices.
The code for the actual grid essentially involves this line:
im = ax[r,c].imshow(info_to_use, vmin=0, vmax=0.6, cmap='gray')
where ax[r,c] is the current subplot axes at row r and column c, and info_to_use is a numpy array of shape (num_rows, num_cols) and has values between 0 and 0.6.
I am wondering if there is a way to convert the code above so that it instead displays bar charts, one per row? Something like this hand-drawn figure:
(The number of columns is not the same in my hand-drawn figure compared to the earlier one.) I know this would result in a very hard-to-read plot if it were embedded into a plot like the first one here. I would have this for a plot with fewer rows, which would make the bars easier to read.
The references that helped me make the first plot above were mostly from:
Python - Plotting colored grid based on values
custom matplotlib plot : chess board like table with colored cells
https://matplotlib.org/3.1.1/gallery/subplots_axes_and_figures/colorbar_placement.html#sphx-glr-gallery-subplots-axes-and-figures-colorbar-placement-py
https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/image_annotated_heatmap.html#sphx-glr-gallery-images-contours-and-fields-image-annotated-heatmap-py
But I'm not sure how to make the jump from these to a bar chart in each row. Or at least something that could mirror it, e.g., instead of shading the full cell gray, only shade as much of it based on the percentage of the vmax?
import numpy as np
from matplotlib import pyplot as plt
a = np.random.rand(10,20)*.6
In a loop, call plt.subplot then plt.bar for each row in the 2-d array.
for i, thing in enumerate(a,1):
plt.subplot(a.shape[0],1,i)
plt.bar(range(a.shape[1]),thing)
plt.show()
plt.close()
Or, create all the subplots; then in a loop make a bar plot with each Axes.
fig, axes = plt.subplots(a.shape[0],1,sharex=True)
for ax, data in zip(axes, a):
ax.bar(range(a.shape[1]), data)
plt.show()
plt.close()
Let's look at a swarmplot, made with Python 3.5 and Seaborn on some data (which is stored in a pandas dataframe df with column lables stored in another class. This does not matter for now, just look at the plot):
ax = sns.swarmplot(x=self.dte.label_temperature, y=self.dte.label_current, hue=self.dte.label_voltage, data = df)
Now the data is more readable if plotted in log scale on the y-axis because it goes over some decades.
So let's change the scaling to logarithmic:
ax.set_yscale("log")
ax.set_ylim(bottom = 5*10**-10)
Well I have a problem with the gaps in the swarms. I guess they are there because they have been there when the plot is created with a linear axis in mind and the dots should not overlap there. But now they look kind of strange and there is enough space to from 4 equal looking swarms.
My question is: How can I force seaborn to recalculate the position of the dots to create better looking swarms?
mwaskom hinted to me in the comments how to solve this.
It is even stated in the swamplot doku:
Note that arranging the points properly requires an accurate transformation between data and point coordinates. This means that non-default axis limits should be set before drawing the swarm plot.
Setting an existing axis to log-scale and use this for the plot:
fig = plt.figure() # create figure
rect = 0,0,1,1 # create an rectangle for the new axis
log_ax = fig.add_axes(rect) # create a new axis (or use an existing one)
log_ax.set_yscale("log") # log first
sns.swarmplot(x=self.dte.label_temperature, y=self.dte.label_current, hue=self.dte.label_voltage, data = df, ax = log_ax)
This yields in the correct and desired plotting behaviour: