This question already has answers here:
How to remove relative shift in matplotlib axis
(2 answers)
Closed 8 years ago.
I am using Python and Pyplot to produce a plot. The y axis of the plot is generated automatically, and works fine.
If the range is small however, the y axis will produce values such as:
0.00005,
0.00010,
0.00015,
0.00020,
0.00025,
0.00030,
and then at the top of the axis, will say:
+1.543e-1
I would prefer that it just explicitly shows the values:
0.15435
0.15440
0.15445
0.15450
0.15455
0.15460
Could someone tell me how to do this please?
Alright, I think I found the total solution:
Here is a quick plot that recreates your problem:
plot((0.15435,0.15440,0.15445,0.15450,0.15455,0.15460),(0.15435,0.15440,0.15445,0.15450,0.15455,0.15460))
The following code (similar to how it was as shown here) should adjust the ticker like you want:
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
gca().yaxis.set_major_formatter(y_formatter)
Related
This question already has answers here:
How to adjust padding with cutoff or overlapping labels
(8 answers)
matplotlib savefig - text chopped off
(3 answers)
Closed 4 months ago.
I have the following code to create a heatmap with seaborn! unfourtunately my y-ticklabels are long names, and are cut off from the figure as shown in the attached image!
seasons = ['yearly','djf','mam','jja','son']
for season_index,season in enumerate(['yearly','djf','mam','jja','son']):
im = sns.heatmap(bias[:,season_index,:],linewidth = 0.5,cmap='coolwarm', annot=True,annot_kws={'fontsize':7, 'fontweight':'bold'})
im.set_xticklabels(['1','2','3','4','5','6','7','8','9'])
im.set_yticklabels(model_list)
plt.savefig(f"figures/bias/yearly_bias_{seasons[season_index]}.png")
plt.close()
I tried changing the figure size with matplotlib, but everytime i did that, the tick labels would rotate 90° and overlap, and in my code it didn't work to reset it with the rotation keyword in the set_yticklabels function.
i also tried this but that had the same result in turning the labels.
Thank you!
plt.tight_layout()
this worked, thank you ver ymuch to Nikita Shabankin!
This question already has answers here:
Matplotlib y axis values are not ordered [duplicate]
(1 answer)
Difference in plotting with different matplotlib versions
(1 answer)
Closed 10 months ago.
The values on the y axis of this plot are too clustered, as seen where I labelled 1 in the picture.
The only was to make the numbers slightly visible is the reduce the value of labelsize= in the tick_params() method but that mades the values so small they are unreadable.
Do I have to plot all the points in the range of my list rainfall in line 16 or can I specifiy which labels I would like to place?
This question already has answers here:
secondary_y=True changes x axis in pandas
(2 answers)
Plot multiple Y axes
(3 answers)
Closed 4 years ago.
I want to add secondary y-axis. I have my data in CSV with three column date, lscc and cc. I want to add LSCC as first y-axis and CC as secondry. so far I have done this
df=pd.read_csv("E29Lsccvalue.csv", index_col='Date' )
plt.ylabel("")
plt.xlabel("Low level Similarity Class Cohesion (LSCC) Evolution")
df.plot(kind="line", marker='o',legend=None)
plt.xticks(rotation=90)
plt.show()
thanks
Within matplotlib I have used twinx() when I want to utilize the existing X-axis I have created, yet plot more data on top with a different Y axis. In your case with df as the first plot object:
axCC = df.twinx() # second axis sharing the same X axis of the original
Then you can include plots, labels, and other parameters referenced to this axis through calls such as:
axCC.set_ylabel("ExampleLabel",color="tab:red")
axCC.plot(xData,yData,color="blue")
Etc, etc.
A fully functional example with more detail is shown here
Although no reproducible date is provided, I guess you can achieve the desired result by doing this:
ax = df.plot(secondary_y='CC')
eventually adding all your ax customization required
edit: dotted line customization
Suppose you need a dotted vertical line at a certain position on your x-axis (in this example, at position 2 from your pandas index), use axvline and ':' as linestyle (dots)
ax = a.plot(secondary_y='Price')
ax.axvline(a.index.values[2], linestyle=':')
This question already has answers here:
matplotlib create broken axis in subplot
(1 answer)
remove part of a plot in matplotlib
(1 answer)
Closed 5 years ago.
I want to define range of x values appeared in plot in python. For example, here is my code:
import matplotlib.pyplot as plt
plt.figure(13)
ax1=plt.subplot(111)
x=[i for i in range(100)]
y=[i**2 for i in x]
ax1.plot(x,y)
However, I want to see in the graph x ranges from 0 to 60 and 80 to 100. How, I can do it in matplot. Actual, problem is more complicated, just removing data doesn't appear to be good solution. I want to change plot.
I tried ax1.set_xlim([0,60]) but want to see from 80 to 100 also.
This question already has answers here:
Heatmap in matplotlib with pcolor?
(4 answers)
Closed 9 years ago.
This is a very basic question. I could not find a satisfactory answer anywhere else so I am writing this up as a question here. I have a matrix, a square matrix about 1300 x 1300. I can use matplotlib to generate a heatmap from it. However, I want the row and column names to show up on the heat map instead of the 0 -- 1300 that normally shows up when i use imshow.
I will put up an example shortly.
You still have not put up your example, but I will give you a quick example of how to change the labels on each axis!
First, put your labels in an array, let's call them y_labels and x_labels
Now here is your code:
ax = pylab.subplots()
ax.set_yticklabels(y_labels)
ax.set_xticklabels(x_labels)
That should do the trick!