How to add drop down to my line chart in dash based on a column in dataframe? - dropdown

I have cleaned the dataframe and plotting these graphs on plotly and work fine on Dash. I want to insert a dropdown for x-axis (i.e, Y and P for both the graphs separately). I am trying with dcc.dropdown but it's not working.
I have been trying with this but am confused about the dcc dropdown. Any help would be appreciated, I am new to Dash!
fig1 = px.line(df_1, x='Y',y=['x','y'])
fig2 = px.line( df_2, x='P',y=['x','y'])
app.layout = html.Div(children=[
# All elements from the top of the page
html.Div([
html.H1(children='...'),
html.Div(children='''
'''
'''),
dcc.Graph(
id='graph1',
figure=fig1
),
]),
# New Div for all elements in the new 'row' of the page
html.Div([
html.H1(children=''),
html.Div(children='''
'''),
dcc.Graph(
id='graph2',
figure=fig2
),
]),
])
if __name__ == '__main__':
app.run_server(debug=True, use_reloader = False)

It is all here https://dash.plotly.com/dash-core-components/dropdown.
Make sure you use dcc.Dropdown instead of dcc.dropdown (lowercase)

Related

Matplotlib sliders on multiple figures

I am writing a Python tool that needs several figures open at the same time, each one with its own widgets (sliders, for the most part). I don't need any interactions across the figures here. Each figure is independent of the other ones, with its own plot and its own sliders affecting only itself.
I can get Matplotlib sliders working fine on a single figure, but I can't get them to work on multiple figures concurrently. Only the sliders of the LAST figure to open are working. The other ones are unresponsive.
I recreated my problem with the simple code below, starting from the example in the Matplotlib.Slider doc. If I run it as-is, only the sliders for the second figure (amplitude) works. The other doesn't. If I invert the two function calls at the bottom, it's the other way around.
I've had no luck googling solutions or pointers. Any help would be much appreciated.
I'm on Python 3.9.12, btw. I can upload a requirements file if someone tries and cannot reproduce the issue. Thank you!
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
# The parametrized function to be plotted
def f(time, amplitude, frequency):
return amplitude * np.sin(2 * np.pi * frequency * time)
# Define initial parameters
init_amplitude = 5
init_frequency = 3
t = np.linspace(0, 1, 1000)
def create_first_fig():
# Create the figure and the line that we will manipulate
fig1, ax1 = plt.subplots()
line1, = ax1.plot(t, f(t, init_amplitude, init_frequency), lw=2, color='b')
ax1.title.set_text('First plot - interactive frequency')
ax1.set_xlabel('Time [s]')
# adjust the main plot to make room for the sliders
fig1.subplots_adjust(left=0.25, bottom=0.25)
# Make a horizontal slider to control the frequency.
axfreq = fig1.add_axes([0.25, 0.1, 0.65, 0.03])
freq_slider = Slider(
ax=axfreq,
label='Frequency [Hz]',
valmin=0,
valmax=30,
valinit=init_frequency,
)
# register the update function with each slider
freq_slider.on_changed(lambda val: update_first_fig(val, fig1, line1))
plt.draw()
plt.pause(0.1)
return fig1
# The function to be called anytime a slider's value changes
def update_first_fig(val, fig, line):
line.set_ydata(f(t, init_amplitude, val))
fig.canvas.draw_idle()
plt.pause(0.1)
def create_second_fig():
# Create the figure and the line that we will manipulate
fig2, ax2 = plt.subplots()
line2, = ax2.plot(t, f(t, init_amplitude, init_frequency), lw=2, color='r')
ax2.title.set_text('Second plot - interactive amplitude')
ax2.set_xlabel('Time [s]')
# adjust the main plot to make room for the sliders
fig2.subplots_adjust(left=0.25, bottom=0.25)
# Make a vertically oriented slider to control the amplitude
axamp = fig2.add_axes([0.1, 0.25, 0.0225, 0.63])
amp_slider = Slider(
ax=axamp,
label="Amplitude",
valmin=0,
valmax=10,
valinit=init_amplitude,
orientation="vertical",
)
# register the update function with each slider
amp_slider.on_changed(lambda val: update_second_fig(val, fig2, line2))
plt.draw()
plt.pause(0.1)
return fig2
# The function to be called anytime a slider's value changes
def update_second_fig(val, fig, line):
line.set_ydata(f(t, val, init_frequency))
fig.canvas.draw_idle()
plt.pause(0.1)
figure1 = create_first_fig()
figure2 = create_second_fig()
plt.show()
I would expect the slider in both figures to work the way it does when I only open the corresponding figure. So far it's only the slider in the figure that's created last that works.
Edit in case someone else looks at this: see Yulia V's answer below. It works perfectly, including in my initial application. The site doesn't let me upvote it because I am too new on here, but it's a perfect solution to my problem. Thanks Yulia V!
You need to save the references to sliders as variables to make it work. No idea why, but this is how matplotlib works.
Specifically, in your functions, you need to have
return freq_slider, fig1
...
return amp_slider, fig2
instead of
return fig1
...
return fig2
and in the main script,
freq_slider, figure1 = create_first_fig()
amp_slider, figure2 = create_second_fig()
instead of
figure1 = create_first_fig()
figure2 = create_second_fig()
Just to illustrate my comment below #Yulia V's answer, it works too if we store the sliders as an attribute of the figure instead of returning them:
def create_first_fig():
...
fig1._slider = freq_slider
...
return fig1
def create_first_fig():
...
fig2._slider = amp_slider
...
return fig2
...
figure1 = create_first_fig()
figure2 = create_second_fig()

Plot line plots of means of grouped boxplots in seaborn

def get_stats_array(dataframe, Method, Cases, stat='mean', round_off=1):
mdf = dataframe
pdp = mdf[mdf['smoker'] == Cases]
if stat == 'mean':
means = pdp.groupby('day').mean()
return round(means,round_off)
elif stat == 'median':
medians = pdp.groupby('day').median()
return round(medians,round_off)
elif stat == 'min':
mins = pdp.groupby('day').min()
return mins
elif stat == 'max':
maxs = pdp.groupby('day').max()
return maxs
else:
return None
import seaborn as sns
sns.set_theme(style="ticks", palette="icefire")
tips = sns.load_dataset("tips")
Mean_Yes = get_stats_array(tips, Method=None, Cases='Yes', stat='mean', round_off=1)['total_bill']
Mean_No = get_stats_array(tips, Method=None, Cases='No', stat='mean', round_off=1)['total_bill']
Mean_array_Thu = [Mean_Yes[0] , Mean_No[0]]
Mean_array_Fri = [Mean_Yes[1] , Mean_No[1]]
Mean_array_Sat = [Mean_Yes[2] , Mean_No[2]]
Mean_array_Sun = [Mean_Yes[3] , Mean_No[3]]
CASES = ['Yes','No']
qf1 = pd.DataFrame([Mean_array_Thu], columns=CASES).assign(day='Thur')
qf2 = pd.DataFrame([Mean_array_Fri], columns=CASES).assign(day='Fri')
qf3 = pd.DataFrame([Mean_array_Sat], columns=CASES).assign(day='Sat')
qf4 = pd.DataFrame([Mean_array_Sun], columns=CASES).assign(day='Sun')
pdf = pd.concat([qf1, qf2, qf3, qf4])
pdf = pd.melt(pdf, id_vars=['day'], var_name=['CASES'])
plt.figure(1, figsize = (25,10))
ax = sns.boxplot(x="day", y="total_bill", hue="smoker", palette=["m", "g"], data=tips, showmeans=True)
sns.despine(offset=10, trim=True)
ax = sns.lineplot(x='day', y='value', data=pdf, style='CASES',ax=ax,color='black')
I was trying to plot a grouped box plot. I tried initially with an example available in seaborn. (Code attached) The data-format is as pandas dataFrame. First I plotted the box plot and then I tried to obtain the means of each group using groupby option but that somehow wasn't working. So I created another separate dataframe with the mean values and tried plotting those. I was able to get the separate line plots of the means of each group but the positioning was wrong. I have attached a figure of the resulting plot. I think there might be a better way to do this with groupby option but I am not sure how. But mainly I want the resulting line-plots of the means properly aligned with the means as well as the boxes. Can anyone help me with this? Please let me know if any more information has to be provided
Alignment issue with grouped-boxplot and line plot of means of each group as shown in the image below:

xlsxwriter: modifying parts of a line in a scatter chart

in the Python package xlsxwriter, is it possible to format a part of a scatter chart series differently than another part? for example, a scatter chart where some sections of the line of a specific series are blue, and other sections of the same line are red. it is certainly possible in Excel itself by modifying specific data points.
I tried using the 'points' option in many combinations without success. I don't know which options are valid for it in a scatter chart.
UPDATE:
here is an example of what I'm trying to achieve. This was created directly in Excel, not through xlsxwriter. Notice how one section of the line is dashed and red, and another is a different thickness. To create it, simply select a data point and use the options in the sidebar to adjust formatting.
I've made an example that I think answers your question.
I'm using Python 3.5 and xlsxwriter 0.9.6.
In chart 1, I changed the color of the markers based on whether they were in a particular group. It's fairly straightforward if chart 1 is what you're looking for.
In chart 2, I show how to hard code a continuous line with different colors (there may be a better way to do this).
import xlsxwriter
import numpy as np
import pandas as pd
dates = pd.DataFrame({'excel_date':pd.date_range('1/1/2016', periods=12, freq='M')})
dates.excel_date = dates.excel_date - pd.datetime(1899, 12, 31)
data = np.array([11,20,25,35,40,48,44,31,25,38,49,60])
selection = np.array([4,5,6,8,11])
#Creating a list - you could hard code these lines if you prefer depending on the size of your series
diff_color_list = list()
for n in range(1, 13):
if n in selection:
diff_color_list.append({'fill':{'color': 'blue', 'width': 3.25}},)
else:
diff_color_list.append({'fill':{'color': 'red', 'width': 3.25}},)
#Workbook Creation
workbook = xlsxwriter.Workbook("test.xlsx")
format = workbook.add_format({'num_format':'mmm-yy'})
worksheet1 = workbook.add_worksheet("testsheet")
worksheet1.write('A1', 'Date')
worksheet1.write('B1', 'Data')
worksheet1.write_column('A2', dates.excel_date, format)
worksheet1.write_column('B2', data)
chart1 = workbook.add_chart({'type': 'scatter'})
# Configure the series.
chart1.add_series({'categories': '=testsheet!$A$2:$A$13',
'values': '=testsheet!$B$2:$B$13',
'points': diff_color_list
})
chart1.set_title ({'name': 'Results'})
chart1.set_x_axis({'name': 'Date'})
chart1.set_y_axis({'name': 'Data'})
chart1.set_legend({'none': True})
# Second chart with alternating line colors
chart2 = workbook.add_chart({'type': 'scatter',
'subtype': 'straight'})
chart2.add_series({'categories': '=testsheet!$A$2:$A$3',
'values': '=testsheet!$B$2:$B$3',
'line':{'color': 'blue'}
})
chart2.add_series({'categories': '=testsheet!$A$3:$A$4',
'values': '=testsheet!$B$3:$B$4',
'line':{'color': 'red'}
})
chart2.add_series({'categories': '=testsheet!$A$4:$A$5',
'values': '=testsheet!$B$4:$B$5',
'line':{'color': 'blue'}
})
chart2.set_title ({'name': 'Results'})
chart2.set_x_axis({'name': 'Date'})
chart2.set_y_axis({'name': 'Data'})
chart2.set_legend({'none': True})
worksheet1.insert_chart('D6', chart1)
worksheet1.insert_chart('L6', chart2)
workbook.close()
The question is a little bit confusing since you talk about changing the color of parts of a line but also about points.
I'm going to assume you are referring to changing the color of points/markers since as far as I know changing the color of line segments in a series isn't possible in Excel.
Anyway, it it possible to change marker colors in a scatter chart using XlsxWriter. For example:
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_scatter.xlsx')
worksheet = workbook.add_worksheet()
# Add the worksheet data that the charts will refer to.
worksheet.write_column('A1', [1, 2, 3, 4, 5, 6])
worksheet.write_column('B1', [15, 40, 50, 20, 10, 50])
# Create a new scatter chart.
chart = workbook.add_chart({'type': 'scatter',
'subtype': 'straight_with_markers'})
# Configure the chart series. Increase the default marker size for clarity
# and configure the series points to
chart.add_series({
'categories': '=Sheet1!$A$1:$A$6',
'values': '=Sheet1!$B$1:$B$6',
'marker': {'type': 'square',
'size': 12},
'points': [
None,
None,
{'fill': {'color': 'green'},
'border': {'color': 'black'}},
None,
{'fill': {'color': 'red'},
'border': {'color': 'black'}},
],
})
# Turn off the legend for clarity.
chart.set_legend({'none': True})
# Insert the chart into the worksheet.
worksheet.insert_chart('D2', chart)
workbook.close()
Output:

Jupyter notebook display two pandas tables side by side

I have two pandas dataframes and I would like to display them in Jupyter notebook.
Doing something like:
display(df1)
display(df2)
Shows them one below another:
I would like to have a second dataframe on the right of the first one. There is a similar question, but it looks like there a person is satisfied either with merging them in one dataframe of showing the difference between them.
This will not work for me. In my case dataframes can represent completely different (non-comparable elements) and the size of them can be different. Thus my main goal is to save space.
I have ended up writing a function that can do this:
[update: added titles based on suggestions (thnx #Antony_Hatchkins et al.)]
from IPython.display import display_html
from itertools import chain,cycle
def display_side_by_side(*args,titles=cycle([''])):
html_str=''
for df,title in zip(args, chain(titles,cycle(['</br>'])) ):
html_str+='<th style="text-align:center"><td style="vertical-align:top">'
html_str+=f'<h2 style="text-align: center;">{title}</h2>'
html_str+=df.to_html().replace('table','table style="display:inline"')
html_str+='</td></th>'
display_html(html_str,raw=True)
Example usage:
df1 = pd.DataFrame(np.arange(12).reshape((3,4)),columns=['A','B','C','D',])
df2 = pd.DataFrame(np.arange(16).reshape((4,4)),columns=['A','B','C','D',])
display_side_by_side(df1,df2,df1, titles=['Foo','Foo Bar']) #we left 3rd empty...
You could override the CSS of the output code. It uses flex-direction: column by default. Try changing it to row instead. Here's an example:
import pandas as pd
import numpy as np
from IPython.display import display, HTML
CSS = """
.output {
flex-direction: row;
}
"""
HTML('<style>{}</style>'.format(CSS))
You could, of course, customize the CSS further as you wish.
If you wish to target only one cell's output, try using the :nth-child() selector. For example, this code will modify the CSS of the output of only the 5th cell in the notebook:
CSS = """
div.cell:nth-child(5) .output {
flex-direction: row;
}
"""
Starting from pandas 0.17.1 the visualization of DataFrames can be directly modified with pandas styling methods
To display two DataFrames side by side you must use set_table_attributes with the argument "style='display:inline'" as suggested in ntg answer. This will return two Styler objects. To display the aligned dataframes just pass their joined HTML representation through the display_html method from IPython.
With this method is also easier to add other styling options. Here's how to add a caption, as requested here:
import numpy as np
import pandas as pd
from IPython.display import display_html
df1 = pd.DataFrame(np.arange(12).reshape((3,4)),columns=['A','B','C','D',])
df2 = pd.DataFrame(np.arange(16).reshape((4,4)),columns=['A','B','C','D',])
df1_styler = df1.style.set_table_attributes("style='display:inline'").set_caption('Caption table 1')
df2_styler = df2.style.set_table_attributes("style='display:inline'").set_caption('Caption table 2')
display_html(df1_styler._repr_html_()+df2_styler._repr_html_(), raw=True)
Combining approaches of gibbone (to set styles and captions) and stevi (adding space) I made my version of function, which outputs pandas dataframes as tables side-by-side:
from IPython.core.display import display, HTML
def display_side_by_side(dfs:list, captions:list):
"""Display tables side by side to save vertical space
Input:
dfs: list of pandas.DataFrame
captions: list of table captions
"""
output = ""
combined = dict(zip(captions, dfs))
for caption, df in combined.items():
output += df.style.set_table_attributes("style='display:inline'").set_caption(caption)._repr_html_()
output += "\xa0\xa0\xa0"
display(HTML(output))
Usage:
display_side_by_side([df1, df2, df3], ['caption1', 'caption2', 'caption3'])
Output:
My solution just builds a table in HTML without any CSS hacks and outputs it:
import pandas as pd
from IPython.display import display,HTML
def multi_column_df_display(list_dfs, cols=3):
html_table = "<table style='width:100%; border:0px'>{content}</table>"
html_row = "<tr style='border:0px'>{content}</tr>"
html_cell = "<td style='width:{width}%;vertical-align:top;border:0px'>{{content}}</td>"
html_cell = html_cell.format(width=100/cols)
cells = [ html_cell.format(content=df.to_html()) for df in list_dfs ]
cells += (cols - (len(list_dfs)%cols)) * [html_cell.format(content="")] # pad
rows = [ html_row.format(content="".join(cells[i:i+cols])) for i in range(0,len(cells),cols)]
display(HTML(html_table.format(content="".join(rows))))
list_dfs = []
list_dfs.append( pd.DataFrame(2*[{"x":"hello"}]) )
list_dfs.append( pd.DataFrame(2*[{"x":"world"}]) )
multi_column_df_display(2*list_dfs)
Here's another variation of the display_side_by_side() function introduced by #Anton Golubev that combines gibbone (to set styles and captions) and stevi (adding space), I added an extra argument to change spacing between tables at run-time.
from IPython.core.display import display, HTML
def display_side_by_side(dfs:list, captions:list, tablespacing=5):
"""Display tables side by side to save vertical space
Input:
dfs: list of pandas.DataFrame
captions: list of table captions
"""
output = ""
for (caption, df) in zip(captions, dfs):
output += df.style.set_table_attributes("style='display:inline'").set_caption(caption)._repr_html_()
output += tablespacing * "\xa0"
display(HTML(output))
display_side_by_side([df1, df2, df3], ['caption1', 'caption2', 'caption3'])
The tablespacing=5 default argument value (shown = 5 here) determines the vertical spacing between tables.
This adds (optional) headers, index and Series support to #nts's answer:
from IPython.display import display_html
def mydisplay(dfs, names=[], index=False):
def to_df(x):
if isinstance(x, pd.Series):
return pd.DataFrame(x)
else:
return x
html_str = ''
if names:
html_str += ('<tr>' +
''.join(f'<td style="text-align:center">{name}</td>' for name in names) +
'</tr>')
html_str += ('<tr>' +
''.join(f'<td style="vertical-align:top"> {to_df(df).to_html(index=index)}</td>'
for df in dfs) +
'</tr>')
html_str = f'<table>{html_str}</table>'
html_str = html_str.replace('table','table style="display:inline"')
display_html(html_str, raw=True)
Here is Jake Vanderplas' solution I came across just the other day:
import numpy as np
import pandas as pd
class display(object):
"""Display HTML representation of multiple objects"""
template = """<div style="float: left; padding: 10px;">
<p style='font-family:"Courier New", Courier, monospace'>{0}</p>{1}
</div>"""
def __init__(self, *args):
self.args = args
def _repr_html_(self):
return '\n'.join(self.template.format(a, eval(a)._repr_html_())
for a in self.args)
def __repr__(self):
return '\n\n'.join(a + '\n' + repr(eval(a))
for a in self.args)
Credit: https://github.com/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/03.08-Aggregation-and-Grouping.ipynb
#zarak code is pretty small but affects the layout of the whole notebook. Other options are a bit messy for me.
I've added some clear CSS to this answer affecting only current cell output. Also you are able to add anything below or above dataframes.
from ipywidgets import widgets, Layout
from IPython import display
import pandas as pd
import numpy as np
# sample data
df1 = pd.DataFrame(np.random.randn(8, 3))
df2 = pd.DataFrame(np.random.randn(8, 3))
# create output widgets
widget1 = widgets.Output()
widget2 = widgets.Output()
# render in output widgets
with widget1:
display.display(df1.style.set_caption('First dataframe'))
df1.info()
with widget2:
display.display(df2.style.set_caption('Second dataframe'))
df1.info()
# add some CSS styles to distribute free space
box_layout = Layout(display='flex',
flex_flow='row',
justify_content='space-around',
width='auto'
)
# create Horisontal Box container
hbox = widgets.HBox([widget1, widget2], layout=box_layout)
# render hbox
hbox
I ended up using HBOX
import ipywidgets as ipyw
def get_html_table(target_df, title):
df_style = target_df.style.set_table_attributes("style='border:2px solid;font-size:10px;margin:10px'").set_caption(title)
return df_style._repr_html_()
df_2_html_table = get_html_table(df_2, 'Data from Google Sheet')
df_4_html_table = get_html_table(df_4, 'Data from Jira')
ipyw.HBox((ipyw.HTML(df_2_html_table),ipyw.HTML(df_4_html_table)))
Gibbone's answer worked for me! If you want extra space between the tables go to the code he proposed and add this "\xa0\xa0\xa0" to the following code line.
display_html(df1_styler._repr_html_()+"\xa0\xa0\xa0"+df2_styler._repr_html_(), raw=True)
I decided to add some extra functionality to Yasin's elegant answer, where one can choose both the number of cols and rows; any extra dfs are then added to the bottom.
Additionally one can choose in which order to fill the grid (simply change fill keyword to 'cols' or 'rows' as needed)
import pandas as pd
from IPython.display import display,HTML
def grid_df_display(list_dfs, rows = 2, cols=3, fill = 'cols'):
html_table = "<table style='width:100%; border:0px'>{content}</table>"
html_row = "<tr style='border:0px'>{content}</tr>"
html_cell = "<td style='width:{width}%;vertical-align:top;border:0px'>{{content}}</td>"
html_cell = html_cell.format(width=100/cols)
cells = [ html_cell.format(content=df.to_html()) for df in list_dfs[:rows*cols] ]
cells += cols * [html_cell.format(content="")] # pad
if fill == 'rows': #fill in rows first (first row: 0,1,2,... col-1)
grid = [ html_row.format(content="".join(cells[i:i+cols])) for i in range(0,rows*cols,cols)]
if fill == 'cols': #fill columns first (first column: 0,1,2,..., rows-1)
grid = [ html_row.format(content="".join(cells[i:rows*cols:rows])) for i in range(0,rows)]
display(HTML(html_table.format(content="".join(grid))))
#add extra dfs to bottom
[display(list_dfs[i]) for i in range(rows*cols,len(list_dfs))]
list_dfs = []
list_dfs.extend((pd.DataFrame(2*[{"x":"hello"}]),
pd.DataFrame(2*[{"x":"world"}]),
pd.DataFrame(2*[{"x":"gdbye"}])))
grid_df_display(3*list_dfs)
test output
Extension of antony's answer If you want to limit de visualization of tables to some numer of blocks by row, use the maxTables variable.
def mydisplay(dfs, names=[]):
count = 0
maxTables = 6
if not names:
names = [x for x in range(len(dfs))]
html_str = ''
html_th = ''
html_td = ''
for df, name in zip(dfs, names):
if count <= (maxTables):
html_th += (''.join(f'<th style="text-align:center">{name}</th>'))
html_td += (''.join(f'<td style="vertical-align:top"> {df.to_html(index=False)}</td>'))
count += 1
else:
html_str += f'<tr>{html_th}</tr><tr>{html_td}</tr>'
html_th = f'<th style="text-align:center">{name}</th>'
html_td = f'<td style="vertical-align:top"> {df.to_html(index=False)}</td>'
count = 0
if count != 0:
html_str += f'<tr>{html_th}</tr><tr>{html_td}</tr>'
html_str += f'<table>{html_str}</table>'
html_str = html_str.replace('table','table style="display:inline"')
display_html(html_str, raw=True)

Imshow subplots share colorbar using AxesGrid. How to plot a grid and set number of ticks

My Program plots three subplot using the same colorbar. Here is the code:
fig=pl.figure()
grid = AxesGrid(fig, 111,nrows_ncols=(3,1),
axes_pad = 0.2,
share_all=True,
label_mode = "L",
cbar_location = "right",
cbar_mode="single",
cbar_size='1%'
)
im = grid[0].imshow(np.random.random((10,50)))
grid.cbar_axes[0].colorbar(im)
im = grid[1].imshow(np.random.random((10,50)))
im = grid[2].imshow(np.random.random((10,50)))
pl.show()
This delivers the following picture:
No I want first to set the number of ticks. E.g. 3 ticks on the y-axis and 10 on the x-axis. Furthermore I want to plot a grid into the picture. But my normal coding works only if I don't use AxisGrid:
fig=pl.figure()
im = imshow(np.random.random((10,50)))
pl.locator_params(axis='x',nbins=20)
pl.locator_params(axis='y',nbins=3)
pl.grid()
pl.show()
What can I do to plot the grid into my subplots and change the number of ticks?
try this:
im = grid[0].imshow(np.random.random((10,50)))
ax = im.get_axes( )
ax.grid( 'on' )
ax.locator_params(axis='x',nbins=20)
ax.locator_params(axis='y',nbins=3)