I would like to combine a few plots, each produced by pyblock, in one figure.
for key in reblock_data.columns.levels[0].values:
pbl.plot.plot_reblocking(reblock_data.xs(key,level=0,axis=1,drop_level=False))
plt.show()
This does not work, but rather produces a seperate figure for each key.
Maybe someone with more background could help me combine those figures.
Here is the respective doc for pyblock: pyblock.plot
The return of the method is class matplotlib.figure.Figure. Does that mean I can not combine two of them?
Related
I am trying to use matplotlib to show some data in a clear way. My current goal is to label the data using two methods: color and shape. The color will be used to represent the data set these specific points come from, while the shape is used to represent whether that example is in category one or two. To visualize this, here is a simple example I drew in PowerPoint:
The reason for doing this instead of simply creating a legend with each specific data set and category stated is I am plotting upwards of 10 data sets, so the legend would remain significantly cleaner and easier to read if color was used for the data sets and shape used for general category (thus the legend would show 10 colors and two shapes, as opposed to 20 different color-shape combinations).
I am currently able to use matplotlib to set the label of the individual data sets by iterating through them and plotting each individually as follows:
import matplotlib.pyplot as plt
ax = plt.figure()
for data in datasets:
scat_plot = ax.scatter(data[x], data[y], label=data[label])
ax.legend()
plt.show()
However, when I attempt to plot the individual shapes and colors and assign them the same label, I am left with plots that do not recognize the two scatter collections as having the same label.
Any suggestions or hints would be greatly appreciated. Thank you.
I am trying to get two different plots as one plot. I will not write down my entire code (is so long), but based on the two small codes below, i get two different time series and I want to put these together in one figure.
My code for the first plot:
plt.figure(figsize=(15,4))
i = plt.plot(july/july.mean(),label='G')
my code for my second plot:
spi3 = pd.read_csv('SPI3.csv',header=0,parse_dates=True)
spi3.plot(y='spi',figsize=(16,4))
Quick dirty fix would be to plot dictionaries at first, only then plot with plt.plot. Also, if you want to plot in the same figure, define figsize only in the first figure you are plotting. (Therefore plt.figure is ommitted completely.)
spi3.plot(y='spi',figsize=(16,4))
plt.plot(july/july.mean(),label='G')
my problem is that I could only find answers for plots sharing the same y-axis units.
My graphs are defined as follows:
#Plot1
sns.set_style("white")
sns.catplot(y="Reaction_cd_positive", x="Flux_cd_positive",
kind="bar",height=4, data=CDP,aspect=1.5)
#Plot2
sns.catplot(y="Reaction_cd_negative",x="Flux_cd_negative",
kind="bar",height=4, data=CDN, aspect=1.5)
Thank you in advance!
Ok, let me translate this. You are using seaborn in a jupyter notebook. You want 2 barplots next to each other within the same figure, instead of two individual figures. Since catplot produces a figure by itself, there are two options.
Create a single catplot with two subplots. To this end you would need to concatenate your two DataFrames into a single one, then use the col argument to split the data into the two subplots.
Create a subplot grid with matplotlib first, then plot a barplot into each of the subplots. This is shown in this question.
I am new at Data Visualization with Python. I want to be able to plot the Groupby() results in a bar chart. I have converted a categorical array using the pd.factorize() function in Python. Then, I created a plot using the results of the groupby function.
Here is my code:
fact=pd.factorize(data['DayOfWeek'])
data['fact'].groupby(data['fact_dow']).count().plot(kind='bar',figsize=(14,8))
plt.show()
The resulting image is:
It looks almost good but the x-labels are the factorized results, I need to map them to their corresponding values.
Any one knows how to do this in a pythonic way? Also, if there are other suggestions as to how to do it, please comment.
If the data['DayOfWeek'] corresponds to the labels, then use plt.xticks(data['DayOfWeek'])
What I'm looking to do is have a pair of 3D figures side by side.
In matplotlib, I was able to create these subplots like so:
ax1 = fig.add_subplot(121, projection='3d')
I'm trying to use Mayavi for my 3D plotting here, because it solves some other problems I'm having, but I can't seem to find a way to plot two figures side-by-side.
Is this even possible?
Every mayavi actor has position/origin/orientation attributes, which you can set to move them to different parts of the scene. You can also add multiple axes and tailor both the ranges over which they display and the labels output. Using a combination of these, you can solve your question; but no, I don't know of a simple "subplot" mechanism.
Other possible alternatives
mlab.screenshot() on separate scenes and combine them in a custom view.
use the canvas frontend inside your own screen widgets, with each side-by-side widget showing a different scene.