Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have cluster labels in one columns and one more column to make comparison or analyze the clusters.
import pandas as pd
parties_and_cluesters = pd.DataFrame({'Parties':['A','B','C','C','A','No Party','B','A'],
'Clusters':['Cluster 2','Cluster 1','Cluster 4','Cluster 4','Cluster 3','Cluster 0','Cluster 3','Cluster 2',]
})
What is the best way to see the outcome? I thought plotting bar-plot but didn't sound good to me. I want to see if clusters reasonable.
Question not clear. If wanted to visualize and feel nice try seaborn count plot
import seaborn as sns
ax = sns.countplot(x="Clusters", data=parties_and_cluesters)
Following your comments
parties_and_cluesters.groupby('Clusters')['Parties'].value_counts().unstack().plot.bar()
In addition to above answer, you may want to display it as stacked. And as I saw from the chat, you can use legend as a seperate part of your plot.
plt.figure(figsize=(20,10))
parties_and_cluesters.groupby('Clusters')["Parties"].value_counts().unstack().plot.bar(stacked=True)
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.gcf().set_size_inches(10, 5)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
click to see the scatter plot
Here in the scatterplot of the iris dataset, we have for example sepal_length plotted against sepal_length then if they are the same value why isn't the graph a linear curve.
In your image, there is no scatterplot between sepal_length and sepal_length. In sns.pairplot, if it is the same feature on both axes of the scatter plot, it defaults to a histogram instead. That is what you are seeing.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The library mplfinance offers a good possibility to perform OHLC plotting with Python/Matplotlib. Nevertheless I want to / have to build a small application that does a kind of OHLC plotting by itself.
I am wondering how I should perform the (huge) amount of vertical and horizontal bars by myself.
Is it the best to do a plt.plot() for all the data I have or is there a more performant way to do this using matplotlib?
Snippet of mplfinance output
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to plot multiple features using pdp.pdp_plot function from the PDPbox python package? The python package is PDPbox https://pdpbox.readthedocs.io/en/latest/api.html
Currently, as I understand, the function can generate a plot for individual features and returns matplotlib figure and axis. It is hard to manage individual axis and assign them a new figure and compile all the axes into a figure.
edit:
Looks like it's not possible to plot multiple features simultaneously. Has someone figured out a way to extract the axis from pdp.pdp_plot function and put it in another figure along with other axes?
According to the documentation: https://pdpbox.readthedocs.io/en/latest/pdp_plot.html
The function returns fig: matplotlib Figure and axes: a dictionary of matplotlib Axes
How can I run the function for multiple features, save axes objects, and put all of them together in one figure?
No, you can only use the pdp.pdp_plot method to plot the partial dependent plot for one feature (documentation: https://pdpbox.readthedocs.io/en/latest/pdp_plot.html)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I like the clean design of the following plots (source). Particularly the offset axes and tick layout.
Apparently they were produced with R. For my own plotting I'm using a combination of matplotlib, pandas.DataFrame.plot and seaborn. Is it possible to create a setting so that plots are by default layouted like this?
Previous attempts: seaborn.despine(offset=10) offsets the axes, but it doesn't format the axes as shown. The following minimal example would be perfect if, axes would be solid black with ticks as above. Grid lines are helpful and should be kept if possible:
seaborn.set_style("whitegrid")
seaborn.load_dataset("iris")["species"].value_counts().plot(kind="bar")
seaborn.despine(offset=10)
Does this achieve what you want?
sns.set(style='ticks', rc={"axes.grid":True}) # to maintain grids with the ticks effect
X = np.random.randn(100)
ax = plt.subplot()
ax.hist(X, color='white', edgecolor='k')
sns.despine(ax=ax, offset=10, trim=True) # offset: the distance to the axis from the plot, trim: to trim off the edges like in R
plt.show()
More in this answer
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How would I make an interactive plot like the one displayed here? I'd like to show an image with x and y slices of the image taken at a point that can be adjusted by clicking on the image.
I know this one was made in Chaco, but since Chaco isn't compatible with python3, just matplotlib or bokeh would be preferable.
Using tacaswells suggestion, I found that the cross_section_2d in bubblegum was just what I was looking for.
First I installed bubblegum from github https://github.com/Nikea/bubblegum.git
Then the following sets up a cross_section image
import matplotlib.pyplot as plt
import numpy as np
from bubblegum.backend.mpl.cross_section_2d import CrossSection
fig= plt.figure()
cs= CrossSection(fig)
img= np.random.rand(100,100)
cs.update_image(img)
plt.show()
Thanks!