This question already has answers here:
Plot negative values on a log scale
(2 answers)
Negative axis in a log plot
(1 answer)
Plot logarithmic axes
(6 answers)
Closed 1 year ago.
Matplotlib appears to not be plotting several points despite me changing the x-limit based on the inputted numbers I am trying to graph. (x-limit because this is a horizontal barplot).
Here is the code:
low = min(df_grouped_underlying['Currency Exposure'].astype(float))
high = max(df_grouped_underlying['Currency Exposure'].astype(float))
fig = plt.figure()
ax = fig.add_subplot()
ax.set_xlim([math.ceil(low-0.5*(high-low)), math.ceil(high+0.5*(high-low))])
bar_1 = ax.barh(df_grouped_underlying.index, df_grouped_underlying['Currency Exposure'].astype(float), label='Currency Exposure')
ax.set(title = 'Currency_Exposure_Underlying_Position',
ylabel = 'Underlying Currency',
xlabel = 'Exposure')
plt.legend(loc="upper right")
plt.savefig('agg_exposure.png', bbox_inches='tight')
plt.show()
Here is the output:
Output of the plot
Related
This question already has answers here:
How to avoid zigzag lines in matplotlib pyplot.plot?
(1 answer)
Matplotlib is graphing a 'zig zag' line when trying to graph polynomial
(2 answers)
Closed 6 days ago.
I am trying to plot some data but the graph does not come out straight across. It will zig-zag to the start or the end and is a mess.
I have this code:
plt.subplots(figsize=(25, 8))
plt.plot(X_test['Date'], prediction_df['Predicted Price'], color='green', marker='o', linestyle='solid')
plt.xlabel("Date")
plt.ylabel("Predicted Price")
plt.show()
I tried changing my x and y values assuming the values were off, but it did nothing. How can I fix the graph output?
This question already has answers here:
How to plot seaborn lineplot and barplot on the same plot with same number of y-axes tickers and both y-axes aligned at 0 in Python
(2 answers)
How to line plot timeseries data on a bar plot
(1 answer)
Problem in combining bar plot and line plot (python)
(2 answers)
Closed 7 months ago.
I am trying to combine a line plot and bar plot in seaborn. Code is as below:)
fig, ax1 = plt.subplots(figsize=(10,6))
sns.barplot(x=df_mergedpa['Day'], y=df_mergedpa['pro_mean'],hue=df_mergedpa['Strain'], ax=ax1)
ax2 = ax1.twinx()
sns.lineplot(x=df_mergedpa['Day'],y=df_mergedpa['ami_mean'],hue=df_mergedpa['Strain'],
marker='o', ax=ax1)
The plot I am getting is as above:
Why the line plot is not rendering properly. It is extending in X-Axis. I am not able to figure out why?
Dataframe looks as below:
This question already has answers here:
matplotlib y-axis label on right side
(4 answers)
using pandas.DataFrame.melt() to plot data with seaborn
(1 answer)
seaborn multiple variables group bar plot
(1 answer)
Closed 8 months ago.
I have the chart below:
Almost everything is fine, except that I want to see the numbers close to the y axis on the right side of the chart.
They represent values that correspond to the labels on y axis as they are. I was thinking that maybe I could just do a mirror for the x axis for one of the plots, but not sure how to do it. Because if I do a mirror I end up doing it for everything.
My code is like that at the moment:
plt.figure(figsize=(12,10))
ax = sns.barplot(x='commission', y="market", hue="is_control", data= df_base.sort_values(by = dimension, ascending = False))
ax = sns.barplot(x="foods and goods", y="market", hue="is_control", data= df_base.sort_values(by = dimension, ascending = False))
plt.title("Treatment vs Control Group {}.".format(country), fontsize=14)
plt.xlabel('% of reduction', fontsize=10)
plt.ylabel('market', fontsize=10)
plt.tight_layout()
for i in ax.containers:
ax.bar_label(i,)
This question already has answers here:
Set xticklabels for all grids, for a plot created with seaborn catplot that uses col_wrap [duplicate]
(1 answer)
How to rotate xticklabels in a seaborn catplot
(2 answers)
subplotting with catplot
(1 answer)
How to remove xticks from a catplot when there's no associated data
(1 answer)
Closed 10 months ago.
I have below code with axes in rows but only the last axes shows the xticks while I want to show the xticks on on each Axes. Please someone help me with this and also guide me how to individually control all the elements of axes.
g = sns.catplot(data = df_full[df_full['Team'].isin(Test_playing_list)], x = 'Match_Year', #palette = sns.color_palette('Paired', 7),
y = 'Win_percent',kind = "bar", height=3, aspect=3, linewidth = 2, row = 'Team', orient="v", facet_kws={'sharey':False, 'sharex':False})
plt.xticks(rotation = 90)
#plt.grid()
plt.show
This question already has answers here:
matplotlib scatterplot with legend
(2 answers)
Matplotlib scatter plot legend
(5 answers)
How to put the legend outside the plot
(18 answers)
Closed 5 years ago.
I have this plot
I want to put legend with color codes horizontally below the plot. Also it will be great if I can chose the color in both the plots and in the legend. Right now it is generated as
fix,axes=plt.subplots(nrows=5,ncols=4, figsize=(20,20))
plots=[]
for i in range(0,5):
for j in range(0,4):
x = list(bdf.groupby('condition').mean(). [bdf.columns[detection_idx]])
y1 = list(df.groupby('condition').mean() [df.columns[aesthetic_idx]])
plots.append(axes[i][j].scatter(x,y1, c = range(0, len(conditions))))
s = list(scenes.values())[i*4+j]
axes[i][j].title.set_text(s)
axes[i][j].set_xlabel('Detection accuracy')
axes[i][j].set_ylabel('Visual aesthetics')
aesthetic_idx+=4
detection_idx+=1
plt.figlegend(tuple(plots), tuple(conditions), loc='lower left', bbox_to_anchor=(0.0, -0.1), ncol=len(conditions))