How can I change the x-axis limits in the contour plot?


Kunal Singhal

I want my plot to also show 7000 on the x-axis, since there are more than 6000 values ​​in the data.

I try to use, set_xlim(right = 7000)but an error pops up

'QuadContourSet' object has no attribute 'set_xlim'

import numpy as np
import matplotlib.pyplot as plt

def contour_plot(filename):

# Reading the porosity data from the dat file

    data = (np.loadtxt("filename"))
    # Making two empty lists to account for the size of each grid block

    x1=[]
    for i in range(0,54):
        x1.append(i*130.75)

    x2=[]
    for j in range(0,44):
        x2.append(j*130.75)
    # Using pyplot.contourf() to make contours using the porosity values and 
    pyplot.colorbar() to show the chart for correlation

    plt.contourf(x1, x2, data[::-1])
    plt.colorbar()
    plt.title("Porosity")
    #plt.savefig('Porosity.png',bbox_inches='tight')
    plot.set_xlim(right = 7000)

contour_plot("Nechelik.dat")
bending

You need to use subplots if you use them ax.set_xlim(), or you can use a single plot using the documentation here .plt.xlim()

For subplots:

ax = plt.subplot(111)
ax.contourf(x1, x2, data[::-1])
ax.set_xlim(right=7000)

or in your case:

plt.contourf(x1, x2, data[::-1])
plt.xlim(right=7000)

Related


How can I change the x-axis limits in the contour plot?

Kunal Singhal I want my plot to also show 7000 on the x-axis, since there are more than 6000 values in the data. I try to use, set_xlim(right = 7000)but an error pops up 'QuadContourSet' object has no attribute 'set_xlim' import numpy as np import matplotlib.p

How can I add an X axis to the plot?

Ann Kribel I'm trying to plot some data, but I don't know how to add date values on the x-axis of the chart. Here is my code: import pandas as pd import numpy as np %matplotlib inline %pylab inline import matplotlib.pyplot as plt pylab.rcParams['figure.figsiz

How can I add an X axis to the plot?

Ann Kribel I'm trying to plot some data, but I don't know how to add date values on the x-axis of the chart. Here is my code: import pandas as pd import numpy as np %matplotlib inline %pylab inline import matplotlib.pyplot as plt pylab.rcParams['figure.figsiz

Change axis limits in plot heatmap

Mathias To visualize the data, I used the heatmap from the plotly.js library. After rendering the heatmap, I want to be able to dynamically change the axis limits. So far I managed to do this for the z axis (color) but not the x or y axis. Here is my attempt:

How can I change the X axis?

Maria friends! Today, I want to ask my next question - how to change the points on the X axis? See what I have. chart1.Series[0].Points.Clear(); chart1.Series[0].Color = Color.Red; chart1.Series[0].BorderWidth = 2; ... for (double i = step; i <= T; i += step)

How can I change the X axis?

Maria friends! Today, I want to ask my next question - how to change the points on the X axis? See what I have. chart1.Series[0].Points.Clear(); chart1.Series[0].Color = Color.Red; chart1.Series[0].BorderWidth = 2; ... for (double i = step; i <= T; i += step)